Skip to content Skip to sidebar Skip to footer

Solvepnpransac Returns Zero Value For Rvecs And Tvecs

I want to find out the rotation and translation vectors for my camera. However, the solvePnPRansac method from the documentation is giving zero matrix for each; it returns values f

Solution 1:

I have used solvePnPRansac with python and I had the same problem. What solvePnPRansac offers compared to solvePnP is that it calculates rvec and tvec based on a choice of 4 or more points from the set of point correspondances that it is given. This choice is made such that the thereby obtained projection will lead to a good enough fit for all given points. If you don't get a good enough fit with any choice of points, the function will return zeros.

You can increase the value for "reprojectError" (8 by default). This will accept a bigger error for the reprojection, so the result is less good but it might be better than no result at all (unless you are aiming for high precision). For example, try:

rvecs, tvecs , inliers = cv2.solvePnPRansac(objp, corners, mtx, dist,reprojectionError=10)

Finally, just for completeness, if you choose a value for reprojectError as high that all points can be taken into consideration while still leading to an acceptable fit, your result is going to be the same as when you use solvePnP.

Solution 2:

I had probably the same problem - getting zeros in rvec, tvec after calling solvePnPRansac. I have found a workaround - use solvePnP instead of solvePnPRansac. It works well for my 4 points. But my program is written in C++, not Python. Here http://docs.opencv.org/trunk/doc/py_tutorials/py_calib3d/py_pose/py_pose.html is some information that I used during the development but I guess you already know it. Hope this helps.

Post a Comment for "Solvepnpransac Returns Zero Value For Rvecs And Tvecs"