Ask Your Question
0

solvePnPRansac CV_32F error

asked 2015-09-09 08:19:13 -0600

Roque gravatar image

updated 2015-09-09 09:01:17 -0600

Hello folks,

First time here, so forgive me if I do something wrong. Of course, if you need more info on the problem, tell me!

I got the following error after running solvePnPRansac:

OpenCV Error: Assertion failed (opoints.depth() == CV_32F) in solvePnPRansac, file /build/buildd/opencv-2.4.8+dfsg1/modules/calib3d/src/solvepnp.cpp, line 284
[ERROR] [WallTime: 1441804199.566629] bad callback: <bound method image_converter.callback of <__main__.image_converter instance at 0x7fbe65cfd050>>
Traceback (most recent call last):
  File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/topics.py", line 702, in _invoke_callback
    cb(msg)
  File "./image_pos_processing.py", line 195, in callback
    self.rvec, self.tvec, inliers = cv2.solvePnPRansac(np.array(self.WorldPointCoords), self.ImageCoords, self.cameraMatrix, self.distCoeffs, self.rvec, self.tvec, self.extrinsicGuess, self.RansacIterations, self.reprojectionError,flags=self.RansacMethod)
error: /build/buildd/opencv-2.4.8+dfsg1/modules/calib3d/src/solvepnp.cpp:284: error: (-215) opoints.depth() == CV_32F in function solvePnPRansac

Here are the parameters I am sending to the algorithm, ordered:

[[ 0.26   0.01  -0.02 ]
 [ 0.025 -0.19   0.005]
 [ 0.015  0.215  0.01 ]
 [ 0.185 -0.015 -0.17 ]]
[[271 382]
 [566 194]
 [301 213]
 [157 158]]
[[ 829.411513    0.        317.462981]
 [   0.        828.855954  246.688352]
 [   0.          0.          1.      ]]
[-0.03096   0.126496  0.002959 -0.004002  0.      ]
-1
-1
False
500
10.0
1

Any tips on this?

Thank you in advance!

EDIT: If I cast the arrays to int type with .astype(int) it returns the same error.

edit retag flag offensive close merge delete

Comments

I think that the problem is due to data type mismatch. You can check this tutorial.

Eduardo gravatar imageEduardo ( 2015-09-11 11:29:27 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2015-09-11 18:06:28 -0600

Roque gravatar image

updated 2015-09-11 18:21:33 -0600

I managed it by casting .astype(np.float32) , and it runs! But, I have a problem: The only think it gives back is the following:

Rotation Matrix:
[[ 1.  0.  0.]
 [ 0.  1.  0.]
 [ 0.  0.  1.]]
[R|t] Matrix:
[[ 1.  0.  0.  0.]
 [ 0.  1.  0.  0.]
 [ 0.  0.  1.  0.]]
Central Point:
[[ 0.]
 [ 0.]
 [ 0.]]

This is the points I grab from the image (imgp):

[[[ 136.]
  [ 270.]]

 [[  65.]
  [ 186.]]

 [[ 140.]
  [ 198.]]

 [[ 261.]
  [ 194.]]]

And these are the World Point Coords:

 [[[ 0.22      ]
  [ 0.005     ]
  [-0.018     ]]

 [[ 0.018     ]
  [ 0.215     ]
  [ 0.01      ]]

 [[ 0.028     ]
  [-0.20999999]
  [ 0.        ]]

 [[ 0.18000001]
  [-0.01      ]
  [-0.16      ]]]

For some reason, the algorithm is doing nothing, or at least it seems. I tried to step down the reprojection error (to as low as 1) and everything stayed the same. With this error, tried to increase the number of iterations, with no results. This is how I am calling the function now:

self.rvec, self.tvec, inliers = cv2.solvePnPRansac(worldp.astype(np.float32), imgp.astype(np.float32), self.cameraMatrix.astype(np.float32), self.distCoeffs.astype(np.float32), self.rvec, self.tvec, useExtrinsicGuess=self.extrinsicGuess, iterationsCount=self.RansacIterations, reprojectionError=self.reprojectionError,flags=self.RansacMethod)

Hope you can help me!

With my best regards,

Pedro

EDIT: I noticed that if I increase reprojection error it works, but I am putting it at like 100. this is way too much I think. What can I do to increase the quality of the measurement?

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-09-09 08:19:13 -0600

Seen: 1,416 times

Last updated: Sep 11 '15