Opencv imbalance map

I am trying to make a map of inconsistencies. I saw the sample code provided by opencv 'stereo_match.cpp' and I wrote the following code. But when I display the left and right image after correction and reassignment, the image becomes black. Can someone tell me where I am doing wrong?

int main(int argc, char* argv[])
{
    Mat img1, img2, g1, g2;
    Mat disp, disp8;
    char* method ="SGBM";
    float scale = 1.f; // don't know why
    //img1 = imread(argv[1]);
    //img2 = imread(argv[2]);
    img1=imread("l1.jpg");
    img2=imread("r1.jpg");
    cvtColor(img1, g1, CV_BGR2GRAY);
    cvtColor(img2, g2, CV_BGR2GRAY);
    Size img_size = img1.size();
    Rect roi1, roi2;
    Mat Q;

    /*reading parameters of ectrinssic & intrinssic file*/
    const char* intrinsic_filename="intrinsics";
    Mat img1r, img2r;
    if( intrinsic_filename )
    {
        FileStorage fs("intrinsics.yml", cv::FileStorage::READ);
        if(!fs.isOpened())
        {
            printf("Failed to open file %s\n");
            return -1;
        }

        Mat M1, D1, M2, D2;
        fs["M1"] >> M1;
        fs["D1"] >> D1;
        fs["M2"] >> M2;
        fs["D2"] >> D2;

        M1 *= scale;
        M2 *= scale;

        fs.open("extrinsics.yml", cv::FileStorage::READ);
        if(!fs.isOpened())
        {
            printf("Failed to open file %s\n");
            return -1;
        }

        Mat R, T, R1, P1, R2, P2;
        fs["R"] >> R;
        fs["T"] >> T;
        stereoRectify( M1, D1, M2, D2, img_size, R, T, R1, R2, P1, P2, Q, CALIB_ZERO_DISPARITY, -1, img_size, &roi1, &roi2 );

        Mat map11, map12, map21, map22;
        initUndistortRectifyMap(M1, D1, R1, P1, img_size, CV_16SC2, map11, map12);
        initUndistortRectifyMap(M2, D2, R2, P2, img_size, CV_16SC2, map21, map22);


        remap(img1, img1r, map11, map12, INTER_LINEAR);
        remap(img2, img2r, map21, map22, INTER_LINEAR);


        //  img1 = img1r;
        // img2 = img2r;

        imshow("left1", img1r);
        imshow("left2", img2r); 

    }
}

output left image} output right image! [original left image] [3]

+4
source share
3 answers

You have not switched the input / output parameters to cvtColor (...) in:

cvtColor(img1, g1, CV_BGR2GRAY);
cvtColor(img2, g2, CV_BGR2GRAY);

g1 and g2 appear to be a gray version of the input images, but they are never used in the following code. Why don't you just try on the other end ?:

g1=imread("l1.jpg");
g2=imread("r1.jpg");
cvtColor(g1, img1, CV_BGR2GRAY);
cvtColor(g2, img2, CV_BGR2GRAY);
0
source

OpenCV , 8- . .

, , Python, :

disp = cv2.normalize(sgbm.compute(ri_l, ri_r), alpha=0, beta=255, \
    norm_type=cv2.NORM_MINMAX, dtype=cv2.CV_8U)

sgmb.compute() - .

0

If remap created only gray images, it means that your internal / external values ​​were bad.

you need to go back to the calibration step and do it again until you exit stereoCalibrate with error <1.

0
source

All Articles