OpenCV 3.1:calibrateCamera“断言失败” - Raspberry Pi / Python

时间:2016-05-04 19:47:07

标签: python opencv

早!

我已经阅读了有关此错误的其他几个主题,但似乎没有一个适用。我正在学习OpenCV,我通常不会编程,所以如果我错过了什么,请随时指出更好的资源和道歉。 我在运行Jessie的Raspberry Pi 2 B上运行OpenCV 3.1和Python 2.7。我在pyimagesearch上根据this article安装了OpenCV,否则它可以正常工作。

我现在正在尝试遵循calibrateCamera教程here。我已经达到了可以获取和保存所有图像(或使用提供的样本)并查看生成的叠加的程度,但是当我使用calibrateCamera到达该行时,我收到以下错误:

  

OpenCV错误:在collectCalibrationData中声明失败(ni == ni1),文件/home/pi/opencv-3.1.0/modules/calib3d/src/calibration.cpp,第3064行   Traceback(最近一次调用最后一次):     文件“findcorners.py”,第38行,in       ret,mtx,dist,rvecs,tvecs = cv2.calibrateCamera(objpoints,imgpoints,gray.shape [:: - 1],None,None)   cv2.error:/home/pi/opencv-3.1.0/modules/calib3d/src/calibration.cpp:3064:错误:(-215)ni == ni1 in function collectCalibrationData

以下是我正在使用的完整代码(目前正在测试提供的示例图像):

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:
    img = cv2.imread(fname)
    gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

    # Find the chess board corners
    ret, corners = cv2.findChessboardCorners(gray, (8,6),None)

    # If found, add object points, image points (after refining them)
    if ret == True:
        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, (7,6), corners2,ret)
        cv2.imshow('img',img)
        cv2.waitKey(500)


ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, gray.shape[::-1], None, None)
np.savez("webcam_calibration_ouput", ret=ret, mtx=mtx, dist=dist, rvecs=rvecs, tvecs=tvecs)
cv2.destroyAllWindows()

0 个答案:

没有答案
相关问题