OpenCV Error through calibration tutorial (solvePnPRansac)

左心房为你撑大大i 提交于 2019-12-24 04:23:33

问题


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


回答1:


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.




回答2:


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)



回答3:


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



来源:https://stackoverflow.com/questions/30271556/opencv-error-through-calibration-tutorial-solvepnpransac

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!