pythonopencvsiftopencv-solvepnp

solvePnP/solvePnPRansac doesn't give good camera position estimation


I am trying to use this code to find camera position by locating flat image in the picture:

https://docs.opencv.org/3.3.1/d1/de0/tutorial_py_feature_homography.html

For this picture it works correctly:

enter image description here

and finds the pattern. I use cv2.projectPoints to draw image over background picture:

enter image description here

But sometimes solvePnP return crazy results, for example for this image:

enter image description here

I get crazy image position if I reproject the pattern:

enter image description here

For this case I've verified SIFT points, they look correctly and match:

enter image description here

I tried to use solvePnPRansac instead of solvePnP, but it doesnt help, estimated position is still stange. What might be the reason and how can I solve this problem?


Solution

  • Ok, I've managed to improve pose estimation in this case by setting distortion matrix to np.array([]) because I already rectify image before SIFT. Same applies to cv2.projectPoints, there is no need to supply distortion coeffitients to this function also.