Opencv StereoRectify 问题

问题描述 投票:0回答:2

使用 opencv 提供的 example。 在我用 RMS 大约 0.66 校准立体对后,我尝试制作 3d 点云。 不幸的是,在我执行stereoRectify之后,我的输入图像变黑。并且没有其他工作是可能的。 可能是因为我校准不当而发生这种情况吗?

Mat img1 = imread(img1_filename, IMREAD_GRAYSCALE);
Mat img2 = imread(img2_filename, IMREAD_GRAYSCALE);

if (img1.empty())
{
    printf("Command-line parameter error: could not load the first input image file\n");
    return -1;
}
if (img2.empty())
{
    printf("Command-line parameter error: could not load the second input image file\n");
    return -1;
}
scale = 1;
if (scale != 1.f)
{
    Mat temp1, temp2;
    int method = scale < 1 ? INTER_AREA : INTER_CUBIC;
    resize(img1, temp1, Size(), scale, scale, method);
    img1 = temp1;
    resize(img2, temp2, Size(), scale, scale, method);
    img2 = temp2;
}

Size img_size = img1.size();

Rect roi1, roi2;

Mat Q;

if (!intrinsic_filename.empty())
{
    // reading intrinsic parameters
    FileStorage fs(intrinsic_filename, FileStorage::READ);
    if (!fs.isOpened())
    {
        printf("Failed to open file %s\n", intrinsic_filename.c_str());
        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(extrinsic_filename, FileStorage::READ);
    if (!fs.isOpened())
    {
        printf("Failed to open file %s\n", extrinsic_filename.c_str());
        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, CV_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);

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

    img1 = img1r;
    img2 = img2r;
    imshow("img1", img1);
    imshow("img2", img2);
    cv::waitKey(0);
}
opencv
2个回答
0
投票

根据: http://answers.opencv.org/question/93090/stereo-rectify-doesnt-rectify-even-with- Correct-m-and-d/

更改 opencv 校准示例中的 StereoCalibrate 标志可以解决此问题。 例如使用:cv::CALIB_RATIONAL_MODEL + cv::CALIB_FIX_K3 + cv::CALIB_FIX_K4 + cv::CALIB_FIX_K5 + cv::CALIB_FIX_K6

另一件事会产生较大的 RMS 误差,但至少正确的重新映射是一起校准内在因素和外在因素。 所以不要使用 cv::CALIB_USE_INTRINSIC_GUESS + cv::CALIB_FIX_INTRINSIC


0
投票

initUn DistretifyMap(M1,D1,R1,P1,img_size,CV_16SC2,map11,map12);

为什么使用CV_16SC2?

尝试 CV_32F

initUn DistretifyMap(M1,D1,R1,P1,img_size,CV_32F,map11,map12);

© www.soinside.com 2019 - 2024. All rights reserved.