2

Can anyone know what is going on with this opencv error ?

cv2.error: /home/desktop/OpenCV/opencv/modules/core/src/matrix.cpp:2294:
 error: (-215) d == 2 && (sizes[0] == 1 || sizes[1] == 1 || 
sizes[0]*sizes[1] == 0) in function create

Line code which raise it is :

rvecs, tvecs, inliers = cv2.solvePnPRansac(objp, corners2, cameraMatrix, dist)

I followed step by step this tutorial: http://docs.opencv.org/master/dc/dbb/tutorial_py_calibration.html

It seems that cameraMatrix is incorrect, but why ?

cameraMatrix looks like this and seems to be as it would (see here):

[[ 535.99484574,    0.        ,  334.33388272],
[   0.        ,  535.99541504,  239.81116973],
[   0.        ,    0.        ,    1.        ]]

From tutorial : cameraMatrix – Input camera matrix

cameraMatrix – Input camera matrix =

nestarz
  • 99
  • 1
  • 10

3 Answers3

2

I think your camera matrix is ok.

The error may be caused by objp or corners.

objp must be array of object points in the object coordinate space, 3xN/Nx3 1-channel or 1xN/Nx1 3-channel, where N is the number of points. std::vector of cv::Point3f can be also passed here.

corners must be an Array of corresponding image points, 2xN/Nx2 1-channel or 1xN/Nx1 2-channel, where N is the number of points. std::vector of cv::Point2f can be also passed here.

Yang Kui
  • 548
  • 5
  • 11
1

Had the same problem, if you follow the tutorial the declaration of objp is not correct - should be like this (w,h being your chessboard dimensions):

objp = np.zeros((w*h, 1, 3), np.float32) 
objp[:,:,:2] = np.mgrid[0:w,  0:h].T.reshape(-1,1,2)
leterhaar
  • 11
  • 1
1

Also be careful to change:

rvecs, tvecs, inliers  = cv2.solvePnPRansac(objp, corners2, mtx, dist)

to either:

_, rvecs, tvecs, inliers = cv2.solvePnPRansac(objp, corners2, mtx, dist)

or

rvecs, tvecs, inliers  = cv2.solvePnPRansac(objp, corners2, mtx, dist)[:-3]

if using Python.

See the thread here: 'Too many values to unpack' with solvePnPRansac() - Pose Estimation

Community
  • 1
  • 1
  • This does not provide an answer to the question. Once you have sufficient [reputation](http://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](http://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](http://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/low-quality-posts/13661857) – jwpfox Sep 14 '16 at 13:33