第 1 部分:更新前
我正在尝试使用两种不同的方法来估计相对位置:solvePNP 和recoverPose,并且似乎R矩阵在某些错误方面看起来不错,但平移向量完全不同。我究竟做错了什么?一般来说,我需要使用这两种方法找到从第 1 帧到第 2 帧的相对位置。
cv::solvePnP(constants::calibration::rig.rig3DPoints, corners1,
cameraMatrix, distortion, rvecPNP1, tvecPNP1);
cv::solvePnP(constants::calibration::rig.rig3DPoints, corners2,
cameraMatrix, distortion, rvecPNP2, tvecPNP2);
Mat rodriguesRPNP1, rodriguesRPNP2;
cv::Rodrigues(rvecPNP1, rodriguesRPNP1);
cv::Rodrigues(rvecPNP2, rodriguesRPNP2);
rvecPNP = rodriguesRPNP1.inv() * rodriguesRPNP2;
tvecPNP = rodriguesRPNP1.inv() * (tvecPNP2 - tvecPNP1);
Mat E = findEssentialMat(corners1, corners2, cameraMatrix);
recoverPose(E, corners1, corners2, cameraMatrix, rvecRecover, tvecRecover);
输出:
solvePnP: R:
[0.99998963, 0.0020884471, 0.0040569459;
-0.0020977913, 0.99999511, 0.0023003994;
-0.0040521105, -0.0023088832, 0.99998915]
solvePnP: t:
[0.0014444492; 0.00018377086; -0.00045027508]
recoverPose: R:
[0.9999900052294586, 0.0001464890570028249, 0.004468554816042664;
-0.0001480011106435358, 0.9999999319097322, 0.0003380476328946509;
-0.004468504991498534, -0.0003387056052618761, 0.9999899588204144]
recoverPose: t:
[0.1492094050828522; -0.007288328116585327; -0.9887787587261805]
第 2 部分:更新后
更新:我改变了R -s 和t -s 在solvePnP之后的组合方式:
cv::solvePnP(constants::calibration::rig.rig3DPoints, corners1,
cameraMatrix, distortion, rvecPNP1, tvecPNP1);
cv::solvePnP(constants::calibration::rig.rig3DPoints, corners2,
cameraMatrix, distortion, rvecPNP2, tvecPNP2);
Mat rodriguesRPNP1, rodriguesRPNP2;
cv::Rodrigues(rvecPNP1, rodriguesRPNP1);
cv::Rodrigues(rvecPNP2, rodriguesRPNP2);
rvecPNP = rodriguesRPNP1.inv() * rodriguesRPNP2;
tvecPNP = rodriguesRPNP2 * tvecPNP2 - rodriguesRPNP1 * tvecPNP1;
这个构图是用相机的实际运动检查的,看起来是正确的。
此外,recoverPose 现在从非平面对象获取点,并且这些点处于一般位置。测试的运动也不是纯旋转以避免退化情况,但平移向量仍然非常不同。
第一帧: 第一帧: 跟踪和匹配绿色点,可以在第二帧上看到(在第二帧上它们是蓝色的): 第二帧: 第二帧: 在恢复姿势的一般位置上的跟踪点:
cv::solvePnP(constants::calibration::rig.rig3DPoints, corners1,
cameraMatrix, distortion, rvecPNP1, tvecPNP1);
cv::solvePnP(constants::calibration::rig.rig3DPoints, corners2,
cameraMatrix, distortion, rvecPNP2, tvecPNP2);
Mat rodriguesRPNP1, rodriguesRPNP2;
cv::Rodrigues(rvecPNP1, rodriguesRPNP1);
cv::Rodrigues(rvecPNP2, rodriguesRPNP2);
rvecPNP = rodriguesRPNP1.inv() * rodriguesRPNP2;
tvecPNP = rodriguesRPNP2 * tvecPNP2 - rodriguesRPNP1 * tvecPNP1;
CMT cmt;
// ...
// ... cmt module finds and tracks points here
// ...
std::vector<Point2f> coords1 = cmt.getPoints();
std::vector<int> classes1 = cmt.getClasses();
cmt.processFrame(imGray2);
std::vector<Point2f> coords2 = cmt.getPoints();
std::vector<int> classes2 = cmt.getClasses();
std::vector<Point2f> coords3, coords4;
// Make sure that points and their classes are in the same order
// and the vectors of the same size
utils::fuse(coords1, classes1, coords2, classes2, coords3, coords4,
constants::marker::randomPointsInMark);
Mat E = findEssentialMat(coords3, coords4, cameraMatrix, cv::RANSAC, 0.9999);
int numOfInliers = recoverPose(E, coords3, coords4, cameraMatrix,
rvecRecover, tvecRecover);
输出:
solvePnP: R:
[ 0.97944641, 0.072178222, 0.18834825;
-0.07216832, 0.99736851, -0.0069195116;
-0.18835205, -0.0068155089, 0.98207784]
solvePnP: t:
[-0.041602995; 0.014756925; 0.025671512]
recoverPose: R:
[0.8115000456601129, 0.03013366385237642, -0.5835748779689431;
0.05045522914264587, 0.9913266281414459, 0.1213498503908197;
0.5821700316452212, -0.1279198133228133, 0.80294120308629]
recoverPose: t:
[0.6927871089455181; -0.1254653960405977; 0.7101439685551703]
recoverPose: numOfInliers: 18
我也尝试过相机静止不动(没有R,没有t)并且R -s 接近但翻译不接近的情况。那么我在这里缺少什么?