Search code examples
pythoncomputer-visioncamera-calibrationopencv3.0pose-estimation

OpenCV Error through calibration tutorial (solvePnPRansac)


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 =


Solution

  • 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.