Ask Your Question
2

undistortPoints with Python

asked 2014-02-19 04:45:05 -0500

m.barz gravatar image

Hello,

I got a problem with the function undistortPoints() when using Python. Hope someone can help me with that...

Here my initialization of camera intrinsics and distortion coef...

K = np.array([[776.65250589, 0, 645.53907335],
    [0, 770.65916345, 374.76352079],
    [0.0,0.0, 1.0]], dtype = np.float64)
dist_coef = np.array([6.47285370e-02, -1.55334472e-01, -1.29510733e-03, 1.95433144e-05, 4.63095096e-02], dtype = np.float32)

My call of undistortPoints is as follows:

cv2.undistortPoints(src, dst, K, dist_coef)

And here the error I get:

cv2.error: /home/michael/workspace/opencv-2.4.8/modules/imgproc/src/undistort.cpp:282: 
error: (-215) CV_IS_MAT(_cameraMatrix) && _cameraMatrix->rows == 3 && 
_cameraMatrix->cols == 3 in function cvUndistortPoints

Thanks in advance!

Kind regards, Michael Barz

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-02-21 02:37:45 -0500

jensenb gravatar image

Your problem here is that you are calling the function with the wrong arguments. The signature for the undistortPoints function in the cv2 namespace is:

undistortPoints(src, cameraMatrix, distCoeffs[, dst[, R[, P]]]) -> dst

Note that the python function signature listed in the online documentation is for the old python interface living in namespace cv (not cv2). It turns out that a lot of the OpenCV functions don't document their method signature in the new cv2 python interface for whatever reason, but they often exist. IPython can help here for determining the correct method signature.

Also note another gotcha with this particular method. It expects the input points to be in a 3 dimensional array, so for example to transform two points you would need something like this:

pts = np.array([[[1.0, 1.0], [1.0, 2.0]]])
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

Asked: 2014-02-19 04:45:05 -0500

Seen: 5,611 times

Last updated: Feb 21 '14