访问中介

http://blog.csdn.net/scottly1/article/details/42705271

http://ieeexplore.ieee.org/xpl/login.jsp?tp=&arnumber=1335420&url=http%3A%2F%2Fieeexplore.ieee.org%2Fxpls%2Fabs_all.jsp%3Farnumber%3D1335420

http://photo.163.com/[email protected]/#m=1&aid=248662080&p=1

http://www.opencv.org.cn/forum.php?mod=viewthread&tid=23388

http://breckon.eu/toby/demos/crossstereo/

http://max.book118.com/html/2014/0410/7500229.shtm

http://ieeexplore.ieee.org/xpl/login.jsp?tp=&arnumber=4359315&url=http%3A%2F%2Fieeexplore.ieee.org%2Fxpls%2Fabs_all.jsp%3Farnumber%3D4359315

http://ieeexplore.ieee.org/xpl/login.jsp?tp=&arnumber=1467541&url=http%3A%2F%2Fieeexplore.ieee.org%2Fxpls%2Fabs_all.jsp%3Farnumber%3D1467541

 

#include 
#include 

using namespace std;
using namespace cv;

#include 
#include <string>

template
string IntToString(T num)
{
    stringstream ss;
    string s;
    ss << num;
    ss >> s;
    return s;
}

struct callparamter{
    Point pt;
    string window_name;
    string trackbar_name;
    vector src;
    vector dst;
    Mat blurresult;
    Mat disp;
    float focus_dist;
    float k;
    float freal;
    float pixelsize;
    float T;
    int Rmax;
    int F;
};
callparamter ptr;

float GetDist(float f, float pixelsize, float T, int  disp)
{
    float z = f * T *1000 / pixelsize / disp;
    return z;
}

void getfiled(float &nerafield, float &farfield, float &sumfield,
    const float det, const float f, const float F, const float L)
{
    nerafield = F*det*L*L;
    farfield = nerafield;
    nerafield  = nerafield / (f*f + F*det*L);
    farfield = farfield / (f*f - F*det*L);
    sumfield = farfield + nerafield;
}

void BlurRidus(float nerafield, float farfield, float L,const float dst,  float &R)
{
    nerafield = L - nerafield;
    farfield = L + farfield;
    if (dst < farfield && dst >nerafield )
    {
        R = 0;
    }
}

void GetBlurImg(const vector &img, vector &blurresult, const Mat &disp, const float focus_dist,const float k, const float freal, const float pixelsize, 
     const float T,  const int Rmax, const float F)
 {
    float u0 = focus_dist;//mm
    float  det = 0.019;
    int a = 1;
    int feq = a * 50;
    int A = 43;
    float nerafield, farfield, sumfield;
    getfiled(nerafield,farfield,sumfield,det, feq, F, u0);

    int stepmax = (int)(Rmax/2)+1;
    int m = img[0].rows;
    int n = img[0].cols;

    int nchannels = img.size();
    for (int c = 0;  c< nchannels; ++c)
    {
        //Mat temp = img[c].clone();
        //Mat disttemp = blurresult[c].clone();
        for(int i = stepmax-1;  i < m-stepmax; ++i)
        {
            for(int j = stepmax-1;  j < n-stepmax; ++j)
            {
                int dispdiff = disp.at(i,j);
                float u = GetDist(freal, pixelsize, T, dispdiff);
                if(u > 2000)
                {
                    u = 2000;
                }
                float B = a/F *abs((u0*(u-a*A)/(u*(u0-a*A)) - 1));
                BlurRidus(nerafield, farfield,u0, u, B);
                B = B*100;
                int R = (int)(k*log(B+1))*2 +1;
                int step = (int)(R/2);
                Mat sub = img[c](Range(i-step, i+step+1),Range(j-step, j+step+1));            
                blurresult[c].at(i,j) = cv::sum(sub)[0]/(R*R);
            }
        }
        //blurresult[c] = disttemp.clone();
    }
 }

float  GetMaxCoef(float umax)
{
    float u0[1] = {0.2*1000};
    float det = 0.019;
    float a = 1;
    float f = a * 50;
    float A = 43;
    float F = 1.0;
    float u = umax;
    u = u*1000;
    float R ;
    for(int i = 0; i< 1; ++i)
    {
        float nerafield, farfield, sumfield;
        getfiled(nerafield, farfield, sumfield,det, f, F, u0[i]);
        R = a/F *abs((u0[i]*(u-a*A)/(u*(u0[i]-a*A)) - 1));
       BlurRidus(nerafield, farfield,u0[i], u,R);
       R *= 100;
    } 
    int MaxCoefficient = (int)(R);
    return MaxCoefficient;
}

void BGblur_Demo(int F, void *param)
{
    //callparamter *ptr = (callparamter*) param;
    GetBlurImg(ptr.src,ptr.dst, ptr.disp, ptr.focus_dist, ptr.k, ptr.freal, ptr.pixelsize, ptr.T,ptr.Rmax,ptr.F);
    merge(ptr.dst, ptr.blurresult);
    imshow(ptr.window_name, ptr.blurresult);

     ptr.F = getTrackbarPos(ptr.trackbar_name, ptr.window_name);
     cout << "F: "<< ptr.F << endl;
}

void on_mouse(int event,int x,int y,int flags,void *ustc)
{
    static Point pre_pt = (-1,-1);
    static Point cur_pt = (-1,-1);
    char temp[16];  
    if (event == CV_EVENT_LBUTTONDOWN)
    {  
        sprintf(temp,"(%d,%d)",x,y);  
        pre_pt = Point(x,y);  
        putText(ptr.blurresult,temp,pre_pt,FONT_HERSHEY_SIMPLEX,0.5,Scalar(0,0,255),1,8);
        circle(ptr.blurresult,pre_pt,2,Scalar(255,0,0,0),CV_FILLED,CV_AA,0); 
        imshow(ptr.window_name,ptr.blurresult);  
        ptr.pt.x = x;
        ptr.pt.y = y;
        cout << "pos:" << ptr.pt.x << " " << ptr.pt.y << endl;
    }  
}

void integral(unsigned char* inputMatrix, unsigned int* outputMatrix, int width, int height)
{  
    unsigned int *columnSum = new unsigned int[width]; // sum of each column
    // calculate integral of the first line  
    for(int i=0;i)
    {  
        outputMatrix[i] = inputMatrix[i];  
        if(i>0)
        {  
            outputMatrix[i] += outputMatrix[i-1];  
        }  
    }  

    for (int i=1;i)
    {  
        int offset = i*width;  
        // first column of each line  
        columnSum[0] +=inputMatrix[offset];  
        outputMatrix[offset] = columnSum[0];  
         // other columns   
        for(int j=1;j)
        {  
            columnSum[j] += inputMatrix[offset+j];  
            outputMatrix[offset+j] = outputMatrix[offset+j-1] + columnSum[j];   
        }  
    }  
    delete []columnSum;
}  

void main()
{
    uchar a[5][5] =
    {
    {17 ,   24 ,    1  ,   8,    15},
    {23 ,    5  ,   7 ,   14  ,  16},
     {4 ,    6  ,  13 ,   20 ,   22},
    {10,    12 ,   19  ,  21,     3},
    {11 ,   18 ,   25 ,    2 ,    9},
    };
    Mat src(5,5,CV_8UC1,&a);
    uchar *data = src.data;
    
    unsigned int  *dst = new unsigned int[5*5];
    integral(data, dst, 5,5);
    for (int i =0; i < 5; ++i)
    {
        for (int j = 0 ; j < 5; ++j)
        {
            cout << dst[i * 5 +j] << " ";
        }
        cout << endl;
    }
//     Mat integralimg(5,5,CV_32SC1, &dst);
//     cout << src <//     cout << integralimg <
    delete []dst;
}
void main1()
{
    Mat img = imread("left.jpg",1);
    string str = "dist.bmp";
    Mat disp = imread(str,0);

    //track
    string window_name = "win";
    string trackbar_name = "Fvalue";
    int Fparamter = 1;
    int maxF = 5;

    float umax = 2.5;
    float Rmax = 21;
    float MaxCoefficient = GetMaxCoef(umax);
    float k = (Rmax-1)/ 2 /log(MaxCoefficient+1);

    float det = 0.019;
    int a = 1;
    int f = a * 50;
    int A = 43;
    float F = Fparamter;
    float u = umax;
    u = u*1000;

    float freal = 4.6;
    float pixelsize = 4.468;
    int m = img.rows;
    int n = img.cols;
    float T = 11* n / 1280.0;
    Mat blurresult = img.clone();

    vector src(3);
    split(img, src);
    vector dst(3);
    split(blurresult, dst);

    //mouseclick
    setMouseCallback(ptr.window_name, on_mouse,0);

    int x = 440;
    int y = 272;
    int dispdiff = disp.at(y,x);
    float focus_dist = GetDist(freal, pixelsize, T, dispdiff);

    ptr.window_name =window_name;
    ptr.trackbar_name = trackbar_name;
    ptr.src = src;
    ptr.focus_dist = focus_dist;
    ptr.F = Fparamter;
    ptr.k = k;
    ptr.pixelsize = pixelsize;
    ptr.Rmax = Rmax;
    ptr.freal = freal;
    ptr.T = T;
    ptr.disp = disp;
    ptr.dst = dst;
    ptr.blurresult = blurresult;
    
    namedWindow(window_name,1);
    createTrackbar( trackbar_name, window_name, &Fparamter, maxF, BGblur_Demo );

    BGblur_Demo(Fparamter, (void*)(&ptr));

    for(;;)
    {
        int c;
        c = waitKey( 20 );
        if( (char)c == 27 )
        { 
            break; 
        }
    }
}

 

你可能感兴趣的:(访问中介)