Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

cv::fisheye::stereoRectify giving black image.

I am trying to create a depth map from a fisheye stereo camera. I have intrinsic and extrinsic data from the camera SDK, so it can be trusted.

When I undistort the image using cv::fisheye::stereoRectify and then cv::fisheye::initUndistortRectifyMap and cv::remap, I get a black image.

When I print the P1 matrix after cv::fisheye::stereoRectify, it looks odd:

//before [284.49261, 0, 425.80771; 0, 285.6832, 395.49429; 0, 0, 1]

//after [108.90381630035, 0, 530.2634673508817, 0; 0, 108.90381630035, -8615.97446825623, 0; 0, 0, 1, 0]

Am I wrong in thinking that these two matrices should be the same? P1 = K1 * T, is that not correct?

If I use:

       cv::Mat identity = cv::Mat::eye(3, 3, CV_64F);
    // Camera 1 Projection Matrix K[I|0]
    cv::Mat PP1(3, 4, cv::DataType<float>::type);
    K1.copyTo(PP1.rowRange(0, 3).colRange(0, 3));
    PP1.at<float>(2, 2) = 1;


    cv::Mat lmapx, lmapy, rmapx, rmapy;
    cv::fisheye::initUndistortRectifyMap(K1, D1, identity, PP1, imgSize, CV_16SC2, lmapx, lmapy);

the undistortion looks good, but I need to rectify as well.

My code is:

leftImg = imread(leftFile_ss, cv::IMREAD_GRAYSCALE);
        rightImg = imread(rightFile_ss, cv::IMREAD_GRAYSCALE);

        //load cal data
        cv::Size imgSize(leftImg.cols, leftImg.rows);

        FileStorage fs("T265.xml", FileStorage::READ);
        cv::Mat K1, K2, D1, D2, R, T;
        fs["K1"] >> K1;
        fs["K2"] >> K2;
        fs["D1"] >> D1;
        fs["D2"] >> D2;
        fs["R"] >> R;
        fs["T"] >> T;

        std::cout << K1 << std::endl;

        double balance = 0.0, fov_scale = 1.0;
        cv::Mat R1, R2, P1, P2, Q;
        cv::fisheye::stereoRectify(K1, D1, K2, D2, imgSize, R, T, R1, R2, P1, P2, Q,
        cv::CALIB_ZERO_DISPARITY);

        std::cout << P1 << std::endl;


        cv::Mat lmapx, lmapy, rmapx, rmapy;
        cv::fisheye::initUndistortRectifyMap(K1, D1, R1, P1, imgSize, CV_16SC2, lmapx, lmapy);
        cv::Mat undist_left;
        cv::remap(leftImg, undist_left, lmapx, lmapy, cv::INTER_LINEAR);


        cv::imshow("undL", undist_left);
        cv::waitKey(0);

What am i doing wrong?

Thank you!

cv::fisheye::stereoRectify giving black image.

I am trying to create a depth map from a fisheye stereo camera. I have intrinsic and extrinsic data from the camera SDK, so it can be trusted.

When I undistort the image using cv::fisheye::stereoRectify and then cv::fisheye::initUndistortRectifyMap and cv::remap, I get a black image.

When I print the P1 matrix after cv::fisheye::stereoRectify, it looks odd:

//before [284.49261, 0, 425.80771; 0, 285.6832, 395.49429; 0, 0, 1]

//after [108.90381630035, 0, 530.2634673508817, 0; 0, 108.90381630035, -8615.97446825623, 0; 0, 0, 1, 0]

Am I wrong in thinking that these two matrices should be the same? P1 = K1 * T, is that not correct?

If I use:

    cv::Mat identity = cv::Mat::eye(3, 3, CV_64F);
    // Camera 1 Projection Matrix K[I|0]
    cv::Mat PP1(3, 4, cv::DataType<float>::type);
    K1.copyTo(PP1.rowRange(0, 3).colRange(0, 3));
    PP1.at<float>(2, 2) = 1;


    cv::Mat lmapx, lmapy, rmapx, rmapy;
    cv::fisheye::initUndistortRectifyMap(K1, D1, identity, PP1, cv::NoArray(), K1, imgSize, CV_16SC2, lmapx, lmapy);

the undistortion looks good, but I need to rectify as well.good. But I am stuck on the Rectify.

My code is:

leftImg = imread(leftFile_ss, cv::IMREAD_GRAYSCALE);
        rightImg = imread(rightFile_ss, cv::IMREAD_GRAYSCALE);

        //load cal data
        cv::Size imgSize(leftImg.cols, leftImg.rows);

        FileStorage fs("T265.xml", FileStorage::READ);
        cv::Mat K1, K2, D1, D2, R, T;
        fs["K1"] >> K1;
        fs["K2"] >> K2;
        fs["D1"] >> D1;
        fs["D2"] >> D2;
        fs["R"] >> R;
        fs["T"] >> T;

        std::cout << K1 << std::endl;

        double balance = 0.0, fov_scale = 1.0;
        cv::Mat R1, R2, P1, P2, Q;
        cv::fisheye::stereoRectify(K1, D1, K2, D2, imgSize, R, T, R1, R2, P1, P2, Q,
        cv::CALIB_ZERO_DISPARITY);

        std::cout << P1 << std::endl;


        cv::Mat lmapx, lmapy, rmapx, rmapy;
        cv::fisheye::initUndistortRectifyMap(K1, D1, R1, P1, imgSize, CV_16SC2, lmapx, lmapy);
        cv::Mat undist_left;
        cv::remap(leftImg, undist_left, lmapx, lmapy, cv::INTER_LINEAR);


        cv::imshow("undL", undist_left);
        cv::waitKey(0);

What am i doing wrong?wrong? How can i rectify these two images?

Thank you!