【发布时间】:2019-04-29 23:49:44
【问题描述】:
我已经设置了两个相机并分别校准它们,之后我使用stereoCalibrate 函数校准了它们。校准似乎工作正常,因为所有返回的重投影误差都在 0.4 到 0.5 的范围内。现在我想从立体图像对中计算出深度图。就我可以遵循的教程而言,我首先需要纠正我的图像,对它们进行灰度化并将它们传递给 StereoBM(或任何其他匹配器)。
据我了解,下面的代码应该纠正并显示两个摄像头的实时图像。
... Load calibration matrices
//compute rectification
Mat R1, R2, P1, P2, Q;
stereoRectify(cameraMatrix_left, distortionCoefficients_left,
cameraMatrix_right, distortionCoefficients_right,
Size(left_camera.get(CAP_PROP_FRAME_WIDTH),
left_camera.get(CAP_PROP_FRAME_HEIGHT)),
R, T, R1, R2, P1, P2, Q, 0, 0.0,
Size(left_camera.get(CAP_PROP_FRAME_WIDTH),
left_camera.get(CAP_PROP_FRAME_HEIGHT)));
//compute undistortion
Mat rmap[2][2];
initUndistortRectifyMap(cameraMatrix_left, distortionCoefficients_left, R1, P1, Size(left_camera.get(CAP_PROP_FRAME_WIDTH), left_camera.get(CAP_PROP_FRAME_HEIGHT)), CV_16SC2, rmap[0][0], rmap[0][1]);
initUndistortRectifyMap(cameraMatrix_right, distortionCoefficients_right, R2, P2, Size(right_camera.get(CAP_PROP_FRAME_WIDTH), right_camera.get(CAP_PROP_FRAME_HEIGHT)), CV_16SC2, rmap[1][0], rmap[1][1]);
while (true) {
if (!right_camera.read(capturedFrame_right))
break;
if (!left_camera.read(capturedFrame_left))
break;
remap(capturedFrame_left, drawFrame_left, rmap[0][0], rmap[0][1], INTER_LINEAR, BORDER_DEFAULT, Scalar());
remap(capturedFrame_right, drawFrame_right, rmap[1][0], rmap[1][1], INTER_LINEAR, BORDER_DEFAULT, Scalar());
cvtColor(drawFrame_left, grayScale_left, COLOR_RGB2GRAY);
cvtColor(drawFrame_right, grayScale_right, COLOR_RGB2GRAY);
imshow(RIGHT_CAMERA, grayScale_right);
imshow(LEFT_CAMERA, grayScale_left);
}
我希望两个图像都得到纠正,如 the documentation of stereoRectify 所示。
但是,它们根本不是。两张图片之间存在明显的垂直差异。 我错过了什么?
【问题讨论】: