Ask Your Question
0

Solve PNP error : EPNP and P3P failed

asked 2014-06-19 10:03:43 -0500

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

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
2

answered 2014-06-23 04:28:11 -0500

JohannesZ gravatar image

One suggestion: try to locate the 3D-object points in den range -1 to 1, the upper left point wold for example be -1.0, -1.0, lower right +1, +1.

edit flag offensive delete link more

Comments

1

With range [-1,1], EPNP, ITERATIVE and P3P send me both same results.

Thanks.

Alexandre Kornmann gravatar imageAlexandre Kornmann ( 2014-06-23 06:38:14 -0500 )edit
1

answered 2020-04-14 03:58:41 -0500

Witek gravatar image

I took the liberty of bringing up this really old question as I seem to have a similar problem, but I do not understand the accepted answer. Should I normalize the image points to [-1,1]? It is not helping at all. If I provide native screen coordinates, EPNP works perfectly for a perfect case, however, when I add even 1 pixel error to just one of the 4 points, the results are crazy. I checked the Matlab version of EPNP and the results are fine.

edit flag offensive delete link more

Comments

1

Can you link the Matlab code for EPnP?

You should open a separate question with some reproducible data/code.

Eduardo gravatar imageEduardo ( 2020-04-14 09:28:42 -0500 )edit

For 4 points, try AP3P method.

Eduardo gravatar imageEduardo ( 2020-04-14 09:38:03 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2014-06-19 10:03:43 -0500

Seen: 1,059 times

Last updated: Apr 14 '20