我正在尝试比较每种SolvePnP可能性之间的精度和耗时:CV_ITERATIVE,CV_EPNP和CV_P3P

我还将我的结果与Matlab EPNP进行了比较。

看来EPNP和P3P失败了:

std::vector<cv::Point2f> imgPoints;
imgPoints.push_back(cv::Point2f(400,188));
imgPoints.push_back(cv::Point2f(400,300));
imgPoints.push_back(cv::Point2f(512,300));
imgPoints.push_back(cv::Point2f(512,188));

double size = 80.0;
std::vector<cv::Point3f> objPoints;
objPoints.push_back(cv::Point3f(0,0,0));
objPoints.push_back(cv::Point3f(0,size,0));
objPoints.push_back(cv::Point3f(size,size,0));
objPoints.push_back(cv::Point3f(size,0,0));

cv::Mat rvec0 = cv::Mat::zeros(3, 1, CV_64FC1);
cv::Mat tvec0 = cv::Mat::zeros(3, 1, CV_64FC1);

cv::Mat rvec1 = cv::Mat::zeros(3, 1, CV_64FC1);
cv::Mat tvec1 = cv::Mat::zeros(3, 1, CV_64FC1);

cv::Mat rvec2 = cv::Mat::zeros(3, 1, CV_64FC1);
cv::Mat tvec2 = cv::Mat::zeros(3, 1, CV_64FC1);

cv::Mat cam, coeff;
cam = (cv::Mat_<double>(3,3) << 700,0,300,0,700,400,0,0,1);
cv::solvePnP(objPoints,imgPoints,cam,coeff,rvec0,tvec0,CV_ITERATIVE);
cv::solvePnP(objPoints,imgPoints,cam,coeff,rvec1,tvec1,CV_P3P);
cv::solvePnP(objPoints,imgPoints,cam,coeff,rvec2,tvec2,CV_EPNP);

cv::Mat rmat0,rmat1,rmat2;
cv::Rodrigues(rvec0,rmat0);
cv::Rodrigues(rvec1,rmat1);
cv::Rodrigues(rvec2,rmat2);

std::cout << "ITERATIVE : Rotation matrix : " << std::endl << rmat0 << std::endl;
std::cout << "ITERATIVE : Tranlation vector : " << std::endl << tvec0 << std::endl << std::endl;

std::cout << "P3P : Rotation matrix : " << std::endl << rmat1 << std::endl;
std::cout << "P3P : Tranlation vector : " << std::endl << tvec1 << std::endl << std::endl;

std::cout << "EPNP : Rotation matrix : " << std::endl << rmat2 << std::endl;
std::cout << "EPNP : Tranlation vector : " << std::endl << tvec2  << std::endl << std::endl;

给我吗 :

迭代:旋转矩阵:[1,-2.196885546074445e-016,9.692430825310778e-016; 2.196885546074445e-016,1,1.012059558506939e-015; -9.692430825310778e-016,-1.012059558506939e-015,1]

迭代的:转化载体:[71.42857142857143; -151.4285714285714; 500]

P3P:旋转矩阵:[1,0,0; 0,1,0; 0、0、1]

P3P:翻译载体:[-3.97771428571427e-015; -4.022285714285698e-015; 9.989999999999962e-017]

EPNP:旋转矩阵:[1,0,0; 0,1,0; 0、0、1]

EPNP:转录载体:[-3.97771428571427e-015; -4.022285714285698e-015; 9.989999999999962e-017]

有什么建议吗?

亚历山大·科恩曼(Alexandre Kornmann)

最佳答案

我有个提示,对我来说有些事情听起来很奇怪:

  • 您为凸轮矩阵的中心点给出了(300,400),因此图像为600 * 800(垂直)?
  • 对于2D点的投影位置,请确保将其以OpenCV方式放置:图像中的(0,0)点位于左上角。
  • 您的点是共面的(平面z = 0),也许solvePnP对此很敏感。
  • 关于opencv - OpenCV的:解决PNP错误,EPNP和P3P失败,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24362058/

    10-10 13:42