使用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);
}