Python Raspberry pi OpenCV错误:(-215)ni==函数CollectionCalibrationData中的ni1
我在raspberry pi 3上运行python 3,并安装了opencv。我拍摄了棋盘上的10幅图像,它检测并显示所有10幅图像,但当它到达最后一行时,它抛出了一个错误。以下是我使用的图像:这是我的代码:Python Raspberry pi OpenCV错误:(-215)ni==函数CollectionCalibrationData中的ni1,python,opencv,Python,Opencv,我在raspberry pi 3上运行python 3,并安装了opencv。我拍摄了棋盘上的10幅图像,它检测并显示所有10幅图像,但当它到达最后一行时,它抛出了一个错误。以下是我使用的图像:这是我的代码: import numpy as np import cv2 import glob # termination criteria criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001) # p
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) 代码: 谢谢@Rui Sebastiao.
我使用的是14 x 10,因此我更改了以下行,至少没有错误:)
objp = np.zeros((6*9,3), np.float32)
objp = np.zeros((14*10, 3), np.float32)
objp[:, :2] = np.mgrid[0:14, 0:10].T.reshape(-1, 2)