1
votes

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?

1
What are you trying to achieve exactly? 'solvePnP' finds an object pose from 3D-2D point correspondences. and from you've shown you don't have 3D points at all.. The python code you shared is for computing the homography matrix which is the perspective transformation between the object in the scene and the trainImage (the one you've top left corner of the last image)Ja_cpp
I need to find camera position. I have 3d points, because I know that piece of paper is on the table, i.e. z = 0, so I have array of 3d points and also array of 2d points on the pattern image, so I can calculate projection rvec and tvec to find camera position in the space.Stepan Yakovenko

1 Answers

3
votes

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.