Ask Your Question

Revision history [back]

Solve PNP error : EPNP and P3P failed

Hi,

I'm trying to compare precision and time consuming between every SolvePnP possibility : CV_ITERATIVE, CV_EPNP, and CV_P3P

I also compared my result with Matlab EPNP.

And it's look like EPNP and P3P failed :

    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;

Give me :

ITERATIVE : Rotation matrix : [1, -2.196885546074445e-016, 9.692430825310778e-016; 2.196885546074445e-016, 1, 1.012059558506939e-015; -9.692430825310778e-016, -1.012059558506939e-015, 1]

ITERATIVE : Tranlation vector : [71.42857142857143; -151.4285714285714; 500]

P3P : Rotation matrix : [1, 0, 0; 0, 1, 0; 0, 0, 1]

P3P : Tranlation vector : [-3.97771428571427e-015; -4.022285714285698e-015; 9.989999999999962e-017]

EPNP : Rotation matrix : [1, 0, 0; 0, 1, 0; 0, 0, 1]

EPNP : Tranlation vector : [-3.97771428571427e-015; -4.022285714285698e-015; 9.989999999999962e-017]

Any suggestion ?

Alexandre Kornmann