Raspberry Pi OpenCV错误:(-215)ni == ni1在函数collectCalibrationData中 [英] Raspberry pi OpenCV error: (-215) ni == ni1 in function collectCalibrationData
问题描述
我在树莓派3上运行python 3并安装了opencv.我拍摄了10张棋盘图像,它检测到所有10张图像并显示它们,但是当到达最后一行时,它将引发错误.这是我使用的图像: https://imgur.com/gallery/IDfHH 这是我的代码:
I'm running python 3 on a raspberry pi 3 and have opencv installed. I took 10 images of a checkerboard, it detects all 10 images and displays them, but when it gets to the last line, it throws an error. Here's the images i used: https://imgur.com/gallery/IDfHH This is my code:
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)
the example assumes that you have a 6x7 chessboard image, i think you have a 6x9. you have to prepare the objp variable for a 6x9 calibration image, so the code has to be like this: objp = np.zeros((6*9,3), np.float32)
代码:
objp = np.zeros((6*9,3), np.float32)
这篇关于Raspberry Pi OpenCV错误:(-215)ni == ni1在函数collectCalibrationData中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!