我正在尝试在 opencv 上校准我的相机。我已经尝试过这段工作正常的代码并识别了 CHessboard 上的点,但是在尝试校准相机时出现错误。我正在使用 python 3.6
我收到这个错误:
error: C:\projects\opencv-
python\opencv\modules\calib3d\src\calibration.cpp:3334: error: (-215)
nimages > 0 in function cv::calibrateCamera
这是我的代码:
import numpy as np
import cv2
numero = 25
nx = 9
ny = 6
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001)
# prepare object points, like (0,0,0), (1,0,0), (2,0,0) ....,(6,5,0)
objp = np.zeros((nx*ny,3), np.float32)
objp[:,:2] = np.mgrid[0:ny,0:nx].T.reshape(-1,2)
# Arrays to store object points and image points from all the images.
objpoints = [] # 3d point in real world space
imgpoints = [] # 2d points in image plane.
#image adress
img = cv2.imread('captureL'+ str(numero)+'.png')
#color to grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
#find and draw ChessboardsCorners
ret, corners = cv2.findChessboardCorners(gray,(nx,ny),None )
if ret == True:
cv2.cornerSubPix(gray, corners, (11, 11), (-1, -1), criteria)
draw_chess = cv2.drawChessboardCorners(img, (nx,ny), corners, ret)
cv2.imshow('video testR',draw_chess)
#camera calibration
ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, gray.shape[::-1], None, None)
cv2.waitKey()
cv2.destroyAllWindows()
你有什么想法吗?因为它,我不再有头发了。谢谢。
最佳答案
我添加了 objpoints.append(objp) 和 imgpoints.append(corners) 来为它们赋值。现在该函数正确返回相机矩阵和所有其他信息。我的错误消息消失了。
关于python - opencv cv2.calibrateCamera错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50202410/