Ask Your Question

Revision history [back]

Here is code to do L-R, R-L, and a consistency check.

d_left.upload(imgL);
d_right.upload(imgR);   

// L-R disparity
scsbp(d_left, d_right, d_dispPre_LR);
dbf(d_dispPre_LR, d_left, d_disp_LR);
d_disp_LR.download(disp_LR);

// Flip horizontally (1) for R-L disparity computation
cv::gpu::flip(d_left, d_left_f, 1);
cv::gpu::flip(d_right, d_right_f, 1);

// R-L disparity
scsbp(d_right_f, d_left_f, d_dispPre_RL_f);
dbf(d_dispPre_RL_f, d_right_f, d_disp_RL_f);
d_disp_RL_f.download(disp_RL_f);

cv::flip(disp_RL_f, disp_RL, 1); // flip back (not supported on GPU)

//////////////////////////////////////////////////////////////////////
// Consistency Check:
//////////////////////////////////////////////////////////////////////
short* dLPtr = (short*) disp_LR.data;
short* dRPtr = (short*) disp_RL.data;
int cstep = disp_LR.cols;

for (int i = 0; i < disp_LR.rows; i++) {
    for (int j = 0; j < disp_LR.cols; j++) {
        short l_d = dLPtr[(i*cstep)+j];
        short r_d = dRPtr[(i*cstep)+j-l_d];
        if (abs(l_d-r_d) > 1) {         
            // set disparity to 0
            dLPtr[(i*cstep)+j] = 0;
        } 
    }
}

Here is code to do L-R, R-L, and a consistency check. check for CSBP.

d_left.upload(imgL);
d_right.upload(imgR);   

// L-R disparity
scsbp(d_left, d_right, d_dispPre_LR);
dbf(d_dispPre_LR, d_left, d_disp_LR);
d_disp_LR.download(disp_LR);

// Flip horizontally (1) for R-L disparity computation
cv::gpu::flip(d_left, d_left_f, 1);
cv::gpu::flip(d_right, d_right_f, 1);

// R-L disparity
scsbp(d_right_f, d_left_f, d_dispPre_RL_f);
dbf(d_dispPre_RL_f, d_right_f, d_disp_RL_f);
d_disp_RL_f.download(disp_RL_f);

cv::flip(disp_RL_f, disp_RL, 1); // flip back (not supported on GPU)

//////////////////////////////////////////////////////////////////////
// Consistency Check:
//////////////////////////////////////////////////////////////////////
short* dLPtr = (short*) disp_LR.data;
short* dRPtr = (short*) disp_RL.data;
int cstep = disp_LR.cols;

for (int i = 0; i < disp_LR.rows; i++) {
    for (int j = 0; j < disp_LR.cols; j++) {
        short l_d = dLPtr[(i*cstep)+j];
        short r_d = dRPtr[(i*cstep)+j-l_d];
        if (abs(l_d-r_d) > 1) {         
            // set disparity to 0
            dLPtr[(i*cstep)+j] = 0;
        } 
    }
}