我在树莓派 3 上运行 python 3 并安装了 opencv。我拍了 10 张棋盘图像,它检测到所有 10 张图像并显示它们,但是当它到达最后一行时,它会抛出错误。这是我使用的图像:https://imgur.com/gallery/IDfHH这是我的代码:
import numpy as np
import cv2
import glob
# termination criteria
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((6*7,3), np.float32)
objp[:,:2] = np.mgrid[0:7,0:6].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.
images = glob.glob('*.jpg')
for fname in images:
print('test')
img = cv2.imread(fname)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
# Find the chess board corners
ret, corners = cv2.findChessboardCorners(gray, (6,9),None)
# If found, add object points, image points (after refining them)
if ret == True:
print('test2')
objpoints.append(objp)
corners2 = cv2.cornerSubPix(gray,corners,(11,11),(-1,-1),criteria)
imgpoints.append(corners2)
# Draw and display the corners
img = cv2.drawChessboardCorners(img, (6,9), corners2,ret)
cv2.imshow('img',img)
cv2.waitKey(500)
print('test3')
cv2.destroyAllWindows()
ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, gray.shape[::-1],None,None)
最佳答案
这个例子假设你有一个 6x7 的棋盘图像,我认为你有一个 6x9。 您必须为 6x9 校准图像准备 objp 变量,因此代码必须如下所示:objp = np.zeros((6*9,3), np.float32)
代码:
objp = np.zeros((6*9,3), np.float32)
关于python - 树莓派 OpenCV 错误 : (-215) ni == ni1 in function collectCalibrationData,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43795220/