2017-05-08 113 views
0

使用opencv提供的exaple。 我校准了0.66左右RMS的立体声对之后,我试着做了一个3d点云。 不幸的是,在我做了stereoRectify之后,我的输入图像变黑了。没有其他工作是可能的。 可能发生这种情况是因为我做了错误的校准?Opencv 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); 
} 

回答

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

,给了较大的均方根误差的另一件事,但至少一个正确的重映射被校准内在和extrinsics在一起。所以请勿使用cv :: CALIB_USE_INTRINSIC_GUESS + cv :: CALIB_FIX_INTRINSIC