I am trying to make disparity map. 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 rectification and remapping the image is black. Can anybody tell me where am I 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](https://i.stack.imgur.com/MBdlt.png)} ![output right image](https://i.stack.imgur.com/DSgd0.png) ![original left image][3]