使用opencv提供的exaple。 在我用0.66左右的RMS校准立体声对后,我尝试制作一个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);
}
答案 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
另一个产生更大RMS误差的事情,但至少正确的重映射是一起校准内在函数和外在函数。 所以不要使用cv :: CALIB_USE_INTRINSIC_GUESS + cv :: CALIB_FIX_INTRINSIC