在立体声校准中,如果我更改立体声相机的分辨率,外部矩阵将如何变化 [英] In stereo calibration, how the extrinsic matrix changes if i change the resolution of stereo camera

查看:143
本文介绍了在立体声校准中,如果我更改立体声相机的分辨率,外部矩阵将如何变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的立体相机具有不同的分辨率1280x480、640x240和320x120. (摄像机将水平同步粘贴的一对同步图像640X480进行流传输,这就是1280x480的原因.)

在以下 link 以校准分辨率为1280 * 480的立体摄像机.

    stereoRectify( M1, D1, M2, D2, img_size, R, T, R1, R2, P1, P2, Q, 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_LINEAR);
    remap(img2, img2r, map21, map22, INTER_LINEAR);

stereoRectify 计算左相机和右相机之间的旋转矩阵R和平移矩阵T.而且,它计算旋转的两个矩阵R1,R2和投影的两个矩阵P1 P2.我将 stereoRectify 的输出用作 initUndistortRectifyMap 的输入,然后重新映射以应用投影.

这是 stackoverflow 答案来解释如何做到这一点.

现在,我得到了左map11,map12和右摄像机map21,map22的两个校正图矩阵.

但是现在我想使用这些摄像机矩阵M1和M2,失真矩阵D1和D2以及外部矩阵R,T,R1,R2,P1和P2分别以较低的分辨率(320x120)校正摄像机图像. PS我没有直接校准分辨率为320 * 120的相机,因为图像太小并且Opencv算法找不到棋盘角进行校准.

我知道失真系数不取决于所观察的场景.因此,它们也属于摄像机的固有参数.无论捕获的图像分辨率如何,它们都保持不变.例如,如果摄像机已经在对320 x 240分辨率的图像进行校准后,同一相机的640 x 480图像可以使用绝对相同的失真系数,而f_x,f_y,c_x和c_y需要适当缩放." 根据 opencv的文档. (我已经测试过并且可以正常工作)

我想知道:我应该如何修改R,T,R1,R2,P1,P2的矩阵,以从1280x480到320x120的较低分辨率进行重新映射?

解决方案

实际上 我更改了P1和P2的矩阵,它们是相机固有矩阵和相机转换矩阵的组合.

我只用320x120将它们除以4.通用公式为:

fx'=(dimx'/dimx)* fx

fy'=(dimy'/dimy)* fy

fx'是新分辨率的值,fx是原始分辨率已经具有的值,dimx'是沿x轴的新分辨率,dimx是原始分辨率.同样适用于风云.

由于所有这些值均以像素坐标表示,因此cp和cy的计算方式类似.

My stereo camera has different resolutions 1280x480, 640x240 and 320x120. (The camera stream a synchronized pair of images 640X480 pasted horizontally that's why is 1280x480).

I have used the algorithm of Opencv3 Stereo Calibration in the following link to calibrate the stereo camera with the resolution of 1280*480.

    stereoRectify( M1, D1, M2, D2, img_size, R, T, R1, R2, P1, P2, Q, 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_LINEAR);
    remap(img2, img2r, map21, map22, INTER_LINEAR);

The stereoRectify computes the rotation matrix R, translation matrix T between left and right camera. And also, it calculates two matrices of rotation R1, R2 and two matrices of projection P1 P2. I used the output of stereoRectify as the input of initUndistortRectifyMap and then remap to apply the projection.

Here is a stackoverflow answer to explain how to do it.

Now I have got the two matrices of rectification map of left map11, map12 and right camera map21, map22.

But now I want to use these camera matrices M1 and M2, distortion matrices D1 and D2, and extrinsic matrices R, T, R1, R2, P1 and P2 to rectify the camera images in a lower resolution (320x120) each. PS I haven't calibrated the camera with the resolution of 320*120 directly because the image is too small and the algorithm of Opencv can't find the chessboard corners to perform the calibration.

I know that "The distortion coefficients do not depend on the scene viewed. Thus, they also belong to the intrinsic camera parameters. And they remain the same regardless of the captured image resolution. If, for example, a camera has been calibrated on images of 320 x 240 resolution, absolutely the same distortion coefficients can be used for 640 x 480 images from the same camera while f_x, f_y, c_x, and c_y need to be scaled appropriately." according the documentation of opencv. ( I tested and it is working)

I want to know: how should I modify the matrices of R, T, R1, R2, P1, P2 to do the remap in a lower resolution from 1280x480 to 320x120?.

解决方案

Actually I change the matrices of P1 and P2 which are the combination of camera intrinsic matrix and camera translation matrix.

I just divide them by 4 for using 320x120. The general formula is:

fx' = (dimx' / dimx) * fx

fy' = (dimy' / dimy) * fy

fx' is the value for your new resolution, fx is the value you already have for your original resolution, dimx' is the new resolution along the x axis, dimx is the original one. The same applies to fy.

cx and cy are calculated analogically because all these values are expressed in pixel coordinates.

这篇关于在立体声校准中,如果我更改立体声相机的分辨率,外部矩阵将如何变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆