我使用openCV的stereoRectify
时遇到很多问题,这些是我的变量:
Mat K_02 = (Mat_<double>(3,3) << 9.597910e+02, 0.000000e+00, 6.960217e+02,
0.000000e+00, 9.569251e+02, 2.241806e+02,
0.000000e+00, 0.000000e+00, 1.000000e+00);
Mat K_03 = (Mat_<double>(3,3) << 9.037596e+02, 0.000000e+00, 6.957519e+02,
0.000000e+00, 9.019653e+02, 2.242509e+02,
0.000000e+00, 0.000000e+00, 1.000000e+00);
Mat D_02 = (Mat_<double>(1,5) << -3.691481e-01, 1.968681e-01, 1.353473e-03, 5.677587e-04, -6.770705e-02);
Mat D_03 = (Mat_<double>(1,5) << -3.639558e-01, 1.788651e-01, 6.029694e-04, -3.922424e-04, -5.382460e-02);
Mat R_02 = (Mat_<double>(3,3) << 9.999758e-01, -5.267463e-03, -4.552439e-03,
5.251945e-03, 9.999804e-01, -3.413835e-03,
4.570332e-03, 3.389843e-03, 9.999838e-01);
transpose(R_02,R_02);
Mat R_03 = (Mat_<double>(3,3) << 9.995599e-01, 1.699522e-02, -2.431313e-02,
-1.704422e-02, 9.998531e-01, -1.809756e-03,
2.427880e-02, 2.223358e-03, 9.997028e-01);
Mat T_02 = (Mat_<double>(1,3) << 5.956621e-02, 2.900141e-04, 2.577209e-03);
Mat T_03 = (Mat_<double>(1,3) << -4.731050e-01, 5.551470e-03, -5.250882e-03);
Mat rotation = cv::Mat::zeros(3, 3, R_03.type());
Mat translation = cv::Mat::zeros(1, 3, T_03.type());
rotation = R_02 * R_03;
translation = T_02 - T_03;
这些变量是使用KITTI数据集获得的,现在我想获得Q矩阵来重建场景,问题是使用stereoRectify
:
Mat R1,R2,P1,P2,Q;
stereoRectify(K_02, D_02, K_03, D_03, size, rotation, translation, R1, R2, P1, P2, Q);
给我一个可怕的断言:
OpenCV Error: Assertion failed ((D.rows == ((flags & CV_GEMM_A_T) == 0 ? A.rows : A.cols)) && (D.cols == ((flags & CV_GEMM_B_T) == 0 ? B.cols : B.rows)) && D.type() == A.type()) in cvGEMM, file /build/buildd/opencv-2.4.9+dfsg/modules/core/src/matmul.cpp, line 3150
我无法调试它,因为gdb(通过Kdevelop)没有找到openCV的源代码(我已经使用存储库安装了它)。我在网上看到如何使用这个函数,但它总是使用stereoCalibrate
函数的输出,所以我不知道哪个是用于定义我的内在函数矩阵的正确类型。
有人可以给我一个如何避免断言的提示吗?
答案 0 :(得分:1)
问题似乎在矩阵translation
中。您有错误,因为您试图将rotation
(3x3
)与translation
(1x3
)相乘。
只需转置translation matrix
使用:
transpose(translation, translation);
或创建T_02
和T_03
而不是Mat_<double>(3, 1)
所以你有一个乘法Mat_<double>(1, 3)