使用Python和OpenCV错误校准网络摄像头 [英] Calibrating Webcam using Python and OpenCV Error

查看:91
本文介绍了使用Python和OpenCV错误校准网络摄像头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这一切还很新,我正在尝试按照

Pretty new to all this and I'm trying to do the calibration for a Webcam following this guide and using the code below. I get the following error ..

OpenCV错误:collectCalibrationData中的声明失败(ni> 0& ni == ni1),文件/build/buildd/opencv-2.4.8+dfsg1/modules/calib3d/src/calibration.cpp,第3193行

OpenCV Error: Assertion failed (ni > 0 && ni == ni1) in collectCalibrationData, file /build/buildd/opencv-2.4.8+dfsg1/modules/calib3d/src/calibration.cpp, line 3193

cv2.error:/build/build/opencv-2.4.8+dfsg1/modules/calib3d/src/calibration.cpp:3193:error:(-215)ni> 0&ni == ni1在函数collectCalibrationData中

cv2.error: /build/buildd/opencv-2.4.8+dfsg1/modules/calib3d/src/calibration.cpp:3193: error: (-215) ni > 0 && ni == ni1 in function collectCalibrationData

有人可以解释这个错误是什么以及如何解决吗?

Can someone explain what this error is and how to fix it?

(底部完全错误)

import numpy as np
import cv2
import glob


criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001)
# Arrays to store object points and image points from all the images.
objpoints = [] # 3d point in real world 
imgpoints = [] # 2d points in image plane.
images = glob.glob('*.png')


objp = np.zeros((6*7,3), np.float32)
objp[:,:2] = np.mgrid[0:7,0:6].T.reshape(-1,2)
objp = objp * 22


for fname in images:

    img = cv2.imread(fname)
    gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
    ret = False
    # Find the chess board corners
    ret, corners = cv2.findChessboardCorners(gray, (6,9))
    # If found, add object points, image points (after refining them)
    if ret == True:
        objpoints.append(objp)
        cv2.cornerSubPix(gray, corners, (11,11), (-1,-1), criteria)

        imgpoints.append(corners)
        # Draw and display the corners 
        cv2.drawChessboardCorners(img, (6,9), corners, ret)
        cv2.imshow('img',img)
        cv2.waitKey(0)

cv2.waitKey(0)
for i in range (1,5):
    cv2.waitKey(1)
    cv2.destroyAllWindows()
    cv2.waitKey(1)


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

OpenCV错误:collectCalibrationData中的声明失败(ni> 0& ni == ni1),文件/build/buildd/opencv-2.4.8+dfsg1/modules/calib3d/src/calibration.cpp,第3193行追溯(最近一次通话):文件",第1行,在运行文件中的文件"/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py",第540行execfile(文件名,命名空间)在第49行中输入文件"/home/students/Test/test.py"ret,mtx,dist,rvecs,tvecs = cv2.calibrateCamera(objpoints,imgpoints,gray.shape [::-1],无,无)cv2.error:/build/build/opencv-2.4.8+dfsg1/modules/calib3d/src/calibration.cpp:3193:错误:(-215)ni> 0&ni == ni1在函数collectCalibrationData中

OpenCV Error: Assertion failed (ni > 0 && ni == ni1) in collectCalibrationData, file /build/buildd/opencv-2.4.8+dfsg1/modules/calib3d/src/calibration.cpp, line 3193 Traceback (most recent call last): File "", line 1, in File "/usr/lib/python2.7/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 540, in runfile execfile(filename, namespace) File "/home/students/Test/test.py", line 49, in ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, gray.shape[::-1],None,None) cv2.error: /build/buildd/opencv-2.4.8+dfsg1/modules/calib3d/src/calibration.cpp:3193: error: (-215) ni > 0 && ni == ni1 in function collectCalibrationData

推荐答案

我遇到了同样的问题,而您的主要错误(我知道是因为我自己做的)是您更改了棋盘格大小(示例中的默认值为7x6),您的尺寸为6x9),但是您忽略了在例程顶部的初始化代码中更改大小

I had this same problem, and your main mistake (which I know because I made it myself) is that you have changed checkerboard size (default in example is 7x6, yours is 6x9), but you have neglected to change the size in the initialization code at the top of the routine

objp = np.zeros((6*7,3), np.float32)
objp[:,:2] = np.mgrid[0:7,0:6].T.reshape(-1,2)

要在多种棋盘格尺寸下使用此功能,您可以像这样调整代码:

To make this work with multiple checkerboard sizes you could adjust the code like so:

# checkerboard Dimensions
cbrow = 5
cbcol = 7

# prepare object points, like (0,0,0), (1,0,0), (2,0,0) ....,(6,5,0)
objp = np.zeros((cbrow * cbcol, 3), np.float32)
objp[:, :2] = np.mgrid[0:cbcol, 0:cbrow].T.reshape(-1, 2)

.
.
.
ret, corners = cv2.findChessboardCorners(gray, (cbcol, cbrow), None)

这篇关于使用Python和OpenCV错误校准网络摄像头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆