问题遇到的现象和发生背景
我觉得是在ret的角点提取的地方,我试着打印出来结果是false,只有一张图片可以使用,换成其他的图片ret都是false
有问题的代码
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001)
#棋盘格模板规格
w = 9
h = 9
# 世界坐标系中的棋盘格点,例如(0,0,0), (1,0,0), (2,0,0) ....,(8,5,0),去掉Z坐标,记为二维矩阵
objp = np.zeros((w*h,3), np.float32)
objp[:,:2] = np.mgrid[0:w,0:h].T.reshape(-1,2)
# 储存棋盘格角点的世界坐标和图像坐标对
objpoints = [] # 在世界坐标系中的三维点
imgpoints = [] # 在图像平面的二维点
#images = cv2.imread('D:\\postgraduate\\Python\\learnpython\\picture_1.jpg')
images = glob.glob('D:\\postgraduate\\Python\\learnpython\\picture_9.jpg')
for fname in images:
img = cv2.imread(fname)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
# 找到棋盘格角点
ret, corners = cv2.findChessboardCorners(gray, (w,h),None)
print(ret)
# 如果找到足够点对,将其存储起来
if ret == True:
cv2.cornerSubPix(gray,corners,(11,11),(-1,-1),criteria)
objpoints.append(objp)
imgpoints.append(corners)
# 将角点在图像上显示
cv2.drawChessboardCorners(img, (w,h), corners, ret)
cv2.namedWindow("findCorners", cv2.WINDOW_NORMAL)
cv2.resizeWindow('findCorners', 600, 600)
cv2.imshow('findCorners',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, gray.shape[::-1], None, None)
运行结果及报错内容
calibration.cpp_3694_ error_ (-215_Assertion failed) nimages _ 0 in function 'cv__calibrateCameraRO'
False
Process finished with exit code 1
我的解答思路和尝试过的方法
我想要达到的结果
希望给一张图片就可以对其进行标定和处理