我正在尝试从使用 OpenCV 和 C++ 从同一相机拍摄的 2 张图像中找到 3D 模型。我遵循了这个方法。我仍然无法纠正 R 和 T 计算中的错误。
图 1:去除背景以消除不匹配
图像 2:仅在 X 方向上平移图像 1 去除背景以消除不匹配
我使用 MATLAB Toolbox 找到了本征相机矩阵 (K)。我发现它是:
K=
[3058.8 0 -500 0 3057.3 488 0 0 1]
所有图像匹配关键点(使用 SIFT 和 BruteForce 匹配,消除不匹配)都与图像中心对齐,如下所示:
obj_points.push_back(Point2f(keypoints1[symMatches[i].queryIdx].pt.x - image1.cols / 2, -1 * (keypoints1[symMatches[i].queryIdx].pt.y - image1.rows / 2)));
scene_points.push_back(Point2f(keypoints2[symMatches[i].trainIdx].pt.x - image1.cols / 2, -1 * (keypoints2[symMatches[i].trainIdx].pt.y - image1.rows / 2)));
从 Point Correspondeces,我发现了在 OpenCV 中使用 RANSAC 的基本矩阵
基本矩阵:
[0 0 -0.0014 0 0 0.0028 0.00149 -0.00572 1 ]
使用以下方法获得的基本矩阵:
E = (camera_Intrinsic.t())*f*camera_Intrinsic;
E 获得:
[ 0.0094 36.290 1.507 -37.2245 -0.6073 14.71 -1.3578 -23.545 -0.442]
E的SVD:
E.convertTo(E, CV_32F);
Mat W = (Mat_<float>(3, 3) << 0, -1, 0, 1, 0, 0, 0, 0, 1);
Mat Z = (Mat_<float>(3, 3) << 0, 1, 0, -1, 0, 0, 0, 0, 0);
SVD decomp = SVD(E);
Mat U = decomp.u;
Mat Lambda = decomp.w;
Mat Vt = decomp.vt;
极线约束的新基本矩阵:
Mat diag = (Mat_<float>(3, 3) << 1, 0, 0, 0, 1, 0, 0, 0, 0);
Mat new_E = U*diag*Vt;
SVD new_decomp = SVD(new_E);
Mat new_U = new_decomp.u;
Mat new_Lambda = new_decomp.w;
Mat new_Vt = new_decomp.vt;
从 SVD 旋转:
Mat R1 = new_U*W*new_Vt;
Mat R2 = new_U*W.t()*new_Vt;
SVD 的翻译:
Mat T1 = (Mat_<float>(3, 1) << new_U.at<float>(0, 2), new_U.at<float>(1, 2), new_U.at<float>(2, 2));
Mat T2 = -1 * T1;
我得到的 R 矩阵是:
R1:
[ -0.58 -0.042 0.813 -0.020 -0.9975 -0.066 0.81 -0.054 0.578]
R2:
[ 0.98 0.0002 0.81 -0.02 -0.99 -0.066 0.81 -0.054 0.57 ]
翻译矩阵:
T1:
[0.543
-0.030
0.838]
T2:
[-0.543
0.03
-0.83]
如有错误,请澄清。
这 4 组 P2 矩阵 R|T 与 P1=[I] 给出了不正确的三角模型。
另外,我认为获得的 T 矩阵是不正确的,因为它应该只有 x 位移而没有 z 位移。
当尝试使用相同的 image1=image2 -> 我得到 T=[0,0,1]。Tz=1 是什么意思?(没有 z 位移,因为两个图像都相同)
我应该将我的关键点坐标与图像中心对齐,还是与校准获得的主焦点对齐?