[英]How to rectify a stereo image pair using opencv?
I have set up two cameras and calibrated them separately, after that I calibrated both using stereoCalibrate
function. 我已经设置了两个摄像头并分别校准,之后我使用
stereoCalibrate
功能进行了校准。 Calibration seemed to work fine, as all returned reprojection errors are in the range of 0.4 to 0.5. 校准似乎工作正常,因为所有返回的重投影误差都在0.4到0.5的范围内。 Now i want to calculate a depth map out of the stereo image pair.
现在我想从立体图像对中计算出深度图。 As far as i could follow the tutorials, i first need to rectify my images, grayscale them and pass them to StereoBM (or any other matcher).
至于我可以按照教程,我首先需要纠正我的图像,灰度图像并将它们传递给StereoBM(或任何其他匹配器)。
As far as i understand the code below should rectify and show two live images of the cameras. 据我所知,下面的代码应该纠正并显示相机的两个实时图像。
... 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);
}
I would expect that both images are rectified as shown on the documentation of stereoRectify . 我希望这两个图像都可以修正,如立体声录制的文档所示。
However, they are simply not. 但是,它们根本就不是。 There is a noticable vertical difference between both pictures.
两张图片之间存在明显的垂直差异。 What did i miss?
我错过了什么?
You need to check your calibration is correct. 您需要检查校准是否正确。 Proper calibration matrix are loaded for that camera, it should provide a rectified image with the above code.
为该摄像机加载适当的校准矩阵,它应该提供具有上述代码的校正图像。
There were guidelines to do stereo calibration in the internet. 有指导在互联网上进行立体声校准。 Few of them listed here.
其中很少有人列在这里。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.