opencv cv2.calibrateCamera error



我正在尝试在opencv上校准我的相机。我已经尝试了这段代码,它可以正常工作并识别 CHessboard 上的点,但在尝试校准相机时出现错误。我正在使用python 3.6

我收到此错误:

error: C:projectsopencv- 
pythonopencvmodulescalib3dsrccalibration.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(来给它们一个值。现在,函数会正确返回相机矩阵和所有其他信息。我的错误消息消失了。

最新更新