【问题标题】:OpenCV Stereo Calibration Rotation MatrixOpenCV 立体校准旋转矩阵
【发布时间】:2015-01-07 18:00:46
【问题描述】:

我正在尝试使用以下 OpenCV 函数使一对相机的输出不失真:

cv::stereoCalibrate(object_points, image_points_left, image_points_right,cameraMatrixLeft, distCoeffsLeft, cameraMatrixRight, distCoeffsRight,cv::Size(sensor_width, sensor_height),R, T, E, F);

cv::stereoRectify(cameraMatrixLeft, distCoeffsLeft, cameraMatrixRight, distCoeffsRight, cv::Size(sensor_width, sensor_height), R, T, R1, R2, P1, P2, Q);

cv::undistortPoints(src_left, dst_left, cameraMatrixLeft, distCoeffsLeft, R1, P1);
cv::undistortPoints(src_right, dst_right, cameraMatrixRight, distCoeffsRight, R2, P2);

据我了解,函数cv::undistortPoints 还应该根据我的立体相机设置使用矩阵R1R2P1P2 来校正输出,即将极线设置为平行于图像 y 轴并裁剪图像。

这是正确的吗?

但是,在src_leftsrc_right 中的点上执行的映射是“倾斜的”,即未失真的输出图像是倾斜的,在图像的边界(尤其是半角)上留下了空白区域。我相信这种倾斜来自旋转矩阵R1R2,并且对应于围绕 z 轴的旋转。

现在这是我的问题:

  • 为什么(校正后的)输出图像没有填满整个图像空间?

【问题讨论】:

    标签: c++ opencv computer-vision calibration


    【解决方案1】:

    在校正和不失真期间,可以根据立体相机的方向平移和/或旋转图像。

    显然,如果您保留转换后的图像的原始分辨率 - 您将丢失边界周围的一些信息。例如。考虑到没有平移,但您必须将其中一张图像顺时针旋转 45 度并使用相同的分辨率 - 角落将是“空白”。

    常见的解决方案是找到一个最大的“内接”矩形并将其放大到原始分辨率。

    您可以使用initUndistortRectifyMap 代替undistortPoints

    对于您的stereoRectify 调用,对initUndistortRectifyMap 的调用将如下所示:

    • 左:initUndistortRectifyMap(cameraMatrixLeft, distCoeffsLeft, R1, P1, cv::Size(sensor_width, sensor_height), CV_32FC1, map_left_1, map_left_2);
    • 右:initUndistortRectifyMap(cameraMatrixRight, distCoeffsRight, R2, P2, cv::Size(sensor_width, sensor_height), CV_32FC1, map_right_1, map_right_2);

    这将为您提供地图,以便致电remap

    • remap(left, left_rectified, map_left_1, map_left_2, INTER_LINEAR, BORDER_CONSTANT);
    • remap(right, right_rectified, map_right_1, map_right_2, INTER_LINEAR, BORDER_CONSTANT);

    【讨论】:

    • 谢谢@Sergei。因为我只有一组稀疏的图像点,所以我想使用'undistortPoints'。
    • 抱歉,我不确定我是否理解您的问题。您在原始解决方案中调用 stereoRectify。我假设它为您提供了所需的输出。因此,我认为调用 initUndistortRectifyMap 没有问题,这似乎可以满足您的需要 - 处理空白边框。我错过了什么?
    • 我认为我没有正确阅读 initUndistortRectifyMap 文档,您建议的方法绝对有意义。再次感谢!
    猜你喜欢
    • 1970-01-01
    • 2013-10-12
    • 2017-10-18
    • 1970-01-01
    • 1970-01-01
    • 2015-03-16
    • 2014-07-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多