I'm trying to execute this code for camera calibration. This code is detecting corners but after that error is coming.
OpenCV Error: Assertion failed (nimages > 0) in unknown function, file ......\modules\calib3d\src\calibration.cpp, line 3415 Traceback (most recent call last): File "C:/Users/uidn1759/PycharmProjects/Camera Calibration/calib.py", line 25, in ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, gray.shape[::-1],None,None) cv2.error: ......\modules\calib3d\src\calibration.cpp:3415: error: (-215) nimages > 0
I'm not able to find where is the problem, if someone can explain, that would be helpful for me. Thanks- Here is the code -
import numpy as np
import cv2
import glob
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001)
objp = np.zeros((6*7,3), np.float32)
objp[:,:2] = np.mgrid[0:7,0:6].T.reshape(-1,2)
objpoints = []
imgpoints = []
images = glob.glob('/usr/local/share/OpenCV/samples/cpp/chess*.jpg')
img = cv2.imread("2.jpg")
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
ret = False
ret, corners = cv2.findChessboardCorners(gray, (7,6))
if ret == True:
cv2.cornerSubPix(gray, corners, (11,11), (-1,-1), criteria)
imgpoints.append(corners)
# Draw and display the corners
cv2.drawChessboardCorners(img, (7,6), corners, ret)
cv2.imshow('img',img)
cv2.imwrite('Corners_detected.jpg', img, None)
cv2.waitKey(500)
cv2.destroyAllWindows()
ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints,
gray.shape[::-1],None,None)
objpoints = []
is the only time it is being objpoints is called beforecalibrateCamera
. You are missing something likeobjpoints .append(objp )
after the lineimgpoints.append(corners)
. – api55