在立体校准中,如果我改变立体相机的分辨率,外部矩阵如何变化

In stereo calibration, how the extrinsic matrix changes if i change the resolution of stereo camera

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

我在下面link使用了Opencv3 Stereo Calibration的算法来标定分辨率为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 的输入,然后重新映射以应用投影。

这里有一个 答案来解释如何做。

现在我得到了左map11、map12和右相机map21、map22的两个校正图矩阵。

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

我知道 "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." 根据 the documentation of opencv。 (我测试过,它正在工作)

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

实际上 我改变了 P1 和 P2 的矩阵,它们是相机固有矩阵和相机平移矩阵的组合。

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

fx' = (dimx' / dimx) * fx

fy' = (dimy' / dimy) * fy

fx' 是新分辨率的值,fx 是原始分辨率的现有值,dimx' 是沿 x 轴的新分辨率,dimx 是原始分辨率。 fy也是一样。

cx和cy是类比计算的,因为这些值都是用像素坐标表示的。

玩了很久 不仅 P1P2 应该缩放,而且 M1M2 (在 OP 的代码中)。

记住,缩放只是左缩放矩阵的两个第一个对角线元素,并保留第三个为1。