使用单个相机进行标记姿势估计时出错

时间:2016-12-12 12:25:26

标签: opencv camera geometry markers pose-estimation

我使用以下OpenCV代码估计方形标记的姿势,并在图像上绘制标记的3个轴。但标记的Z轴时间旋转180度,如下图所示。如何使z轴稳定?

// Marker world coordinates
vector<Point3f> objecPoints;
objecPoints.push_back(Point3f(0, 0, 0));
objecPoints.push_back(Point3f(0, 2.4, 0));
objecPoints.push_back(Point3f(2.4, 2.4, 0));
objecPoints.push_back(Point3f(2.4, 0.0, 0));

// 2D image coordinates of 4 marker corners. They are arranged in the same order for each frame
vector<Point2f> marker2DPoints;

// Calculate Rotation and Translation
cv::Mat Rvec;
cv::Mat_<float> Tvec;
cv::Mat raux, taux;
cv::solvePnP(objecPoints, marker2DPoints, camMatrix, distCoeff, raux, taux);

// Draw marker pose on the image
vector<Point3f> axisPoints3D;
axisPoints3D.push_back(Point3f(0, 0, 0));
axisPoints3D.push_back(Point3f(2.4, 0, 0));
axisPoints3D.push_back(Point3f(0, 2.4, 0));
axisPoints3D.push_back(Point3f(0, 0, 2.4));

vector<Point2f> axisPoints2D;

// Take the camMatrix and distCoeff from camera calibration results
projectPoints(axisPoints3D, Rvec, Tvec, camMatrix, distCoeff, axisPoints2D);

line(srcImg, axisPoints2D[0], axisPoints2D[1], CV_RGB(0, 0, 255), 1, CV_AA);
line(srcImg, axisPoints2D[0], axisPoints2D[2], CV_RGB(0, 255, 0), 1, CV_AA);
line(srcImg, axisPoints2D[0], axisPoints2D[3], CV_RGB(255, 0, 0), 1, CV_AA);

Pose estimation results at time t Pose estimation results at time t+1

1 个答案:

答案 0 :(得分:0)

作为评论,这可能会更好,但我没有足够的声誉。我认为这可能是由于solvePnP获取标签坐标的顺序而发生的。 此外,由于solvePnP只是试图将3D平面上的4个点匹配到图像中的4个2D点,​​因此有多种解决方案。标签可以绕其上轴旋转,也可以倒置翻转。 solvePnP并不知道所提供的点是向上的方向。

由于稳定的标签检测算法应该能够以稳定的顺序将角落馈送到姿势估计代码,所以我有一种预感,即solvePnP对于这个问题有点过于笼统。

编辑:角落的顺序很重要,solvePnP给出的解决方案依赖于它。也许生成角点的算法不能以一致的顺序提供角点?请分享tags.points的输出