Kinect + OpenCV : Unable to fetch rotational vectors using cv2.solvePnP in python

asked 2015-11-26 01:36:28 -0600

I am working on a project where I require to track aerial objects and calculate the six degree of freedom.

  1. I am currently tracking colored balls , and calculating their center in rgb_frame, and using the center values to find the depth in the depth_frame.

  2. After finding the depth(Z) in real-world co-ords,I am calculating the real-world X and Y using equations: X = (Zu)/fx and Y = (Zv)/fy , where fx,fy are the focal length obtained from the kinect's intrinsic params ,and u and v in this case are the center's x,y values.

  3. I am treating (u,v) as image point and (X,Y,Z) as image point and feeding into this method: solvePnP

    obj_pts = np.array([[X,Y,Z]],np.float64) img_pts = np.array([[u,v]],np.float64)

    ret,rvecs,tvecs = cv2.solvePnP(obj_pts,img_pts,camera_matrix2,np_dist_coefs)

I expect to find the rvecs which I will use as input for:

cv2.Rodrigues(rvecs)

to get the euler angles namely, pitch, yaw, roll.

I am presently having issues with the solvePnP call, which gives me the following error:

/opencv-3.0.0/modules/calib3d/src/solvepnp.cpp:61: error: (-215) npoints >= 0 && npoints == std::max(ipoints.checkVector(2, CV_32F), ipoints.checkVector(2, CV_64F)) in function solvePnP

I also understand that sending just the center's object and image points is not recommended. By this is my first step towards the realization. I intend to use feature detectors like SIFT to make it more interesting later.

Can anyone please suggest on my approach and help me accomplish finding the six degrees of freedom:

forward/back, up/down, left/right, pitch, yaw, roll.

edit retag flag offensive close merge delete

Comments

1

SolvePnP requires to have at least 4 points (3 points for P3P algorithm I think) to be able to compute the rotation and translation vector that will contain the transformation from the world frame to the camera frame.

With only one point, you cannot have an orientation, you just have a translation.

Eduardo gravatar imageEduardo ( 2015-11-26 04:13:53 -0600 )edit

Thank you @Eduardo...that did the trick. I was lazy at feeding all the points of interests at one and just using the center pixel. Putting all the points does the trick.

knapsack01 gravatar imageknapsack01 ( 2015-11-27 12:56:00 -0600 )edit