cv::SolvePnP with CV_ITERATIVE under OpenCV 3.3

asked 2017-11-06 11:32:36 -0500

fab_cut gravatar image

updated 2017-11-06 15:14:20 -0500

Hi all, I have a problem with the function cv::SolvePnP. The same function works PERFECTLY under OpenCV 3.1 with three points (markers). This is the call:

cv::solvePnP(Markers3DCoord_world,ImagePoints,Mat(IntrinsicMatx),Mat(Distortionparams),rot_vec_l,vec_tras_l,true,cv::CV_ITERATIVE); Markes3DCoord_world are std::vector of Point3f, whereas ImagePoints are std::vector of Point2f

I know that the problem per se would be ambigous with three points (P3P problem), but using the Iterative optimization of the Levenberg-Marquardt optimization algorithm (flags set to true and method: CV_ITERATIVE) if I use a good initial guess I obtain the solution that I am seeking under OpenCV 3.1. Now the problem is that the same method on OpenCV 3.3 seems to crash. Why is that? If i use the same method under OpenCV 3.3 but with a higher n° of points = 12 ( as in the case of a chessboard tracking) it works perfectly. In this case the call is: flag_err=solvePnP(Markers3DCoord_world,ImagePoints,Mat(IntrinsicMatx),Mat(Distortionparams),rot_vec_l,vec_tras_l,false,cv::CV_ITERATIVE);

What's the matter with solvePnP under OpenCV 3.3?

Thanks

edit retag flag offensive close merge delete

Comments

In OpenCV 3.3, the minimum number of points is 4 for solvePnP (it has been changed, there is an assert).

With an initial guess with the iterative method, what is the minimum number of points? With a good initial pose, does it make sense mathematically to use one point / two points / three points?

Eduardo gravatar imageEduardo ( 2017-11-07 07:52:53 -0500 )edit

@Eduardo Thanks for your reply. With the iterative method 3 points are enough to converge to a local minimum. As for the second question, if you have more than one camera you might be in the condition of properly solving a standard absolute orientation problem ( link text which can provides you a good initial guess for the subsequent exterior orientation problem or PnP problem link text

fab_cut gravatar imagefab_cut ( 2017-11-08 05:05:25 -0500 )edit

@fab_cut If you have built OpenCV from source, it should be easy to change the assert and add the case 3 points with an initial guess with the iterative method (the file is in modules/calib3d/src/solvepnp.cpp).

I think the following changes can be made for the next OpenCV release: accept 3 points if there is an initial guess and the iterative method is used, otherwise 4 points are required for solvePnP.

Thanks for the report.

Eduardo gravatar imageEduardo ( 2017-11-09 07:46:23 -0500 )edit