![](/img/trans.png)
[英]Python and OpenCV: -215:Assertion failed error when trying to call calibrateCamera
[英]error: (-215) nimages > 0 in function calibrateCamera using Python and OpenCV
我正在嘗試根據 opencv 示例中給出的示例校准我的網絡攝像頭,但是當我運行此處提供的代碼時:
def caliLeftCam():
args, img_mask = getopt.getopt(sys.argv[1:], '', ['save=', 'debug=', 'square_size='])
args = dict(args)
try: img_mask = img_mask[0]
except: img_mask = '../cpp/img*.jpg'
img_names = glob(img_mask)
debug_dir = args.get('--debug')
square_size = float(args.get('--square_size', 1.0))
pattern_size = (7, 5)
pattern_points = np.zeros( (np.prod(pattern_size), 3), np.float32 )
pattern_points[:,:2] = np.indices(pattern_size).T.reshape(-1, 2)
pattern_points *= square_size
obj_points = []
img_pointsL = []
h, w = 0, 0
for fn in img_names:
print "processing %s..." % fn,
imgL = cv2.imread(fn, 0)
h, w = imgL.shape[:2]
found, corners = cv2.findChessboardCorners(imgL, pattern_size)
if found:
term = ( cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_COUNT, 30, 0.1 )
cv2.cornerSubPix(imgL, corners, (5, 5), (-1, -1), term)
if debug_dir:
vis = cv2.cvtColor(imgL, cv2.COLOR_GRAY2BGR)
cv2.drawChessboardCorners(vis, pattern_size, corners, found)
path, name, ext = splitfn(fn)
cv2.imwrite('%s/%s_chess.bmp' % (debug_dir, name), vis)
if not found:
print "chessboard not found"
continue
img_pointsL.append(corners.reshape(-1, 2))
obj_points.append(pattern_points)
print 'ok'
rmsL, cameraL_matrix, dist_coefsL, rvecsL, tvecsL = cv2.calibrateCamera(obj_points, img_pointsL, (w, h))
我收到這個錯誤:
Traceback (most recent call last):
File "/home/sabrine/Downloads/opencv-2.4.9/samples/python2/Memo.py", line 293, in <module>
Img_pointsL, Cam_MatL, DisL = caliLeftCam()
File "/home/sabrine/Downloads/opencv-2.4.9/samples/python2/Memo.py", line 124, in caliLeftCam
rmsL, cameraL_matrix, dist_coefsL, rvecsL, tvecsL = cv2.calibrateCamera(obj_points, img_pointsL, (w, h))
error: /build/buildd/opencv-2.4.8+dfsg1/modules/calib3d/src/calibration.cpp:3415:
error: (-215) nimages > 0 in function calibrateCamera
這個錯誤是什么意思? 我該如何解決?
該錯誤表示作為參數提供的向量之一為空。
如果未滿足所有條件,則該函數具有阻止您使用它的斷言。 這次它檢查是否有足夠的圖像點( nimages > 0
必須為真)。
重新檢查函數 "cv2.findChessboardCorners(image, (nx, ny))/ cv2.drawChessboardCorners(image, pattern_size)" 的 nx 和 ny (pattern_size) 的值,這應該是棋盤中的內角行和列數. 它對我有用。
我知道我為時已晚,但希望它可以幫助其他人。 替換以下行:
except: img_mask = '../cpp/img*.jpg'
和:
except: img_mask = './cpp/img*.jpg'
就我而言,我沒有在示例圖片中使用足夠大的棋盤格。 打印 7x10 棋盤而不是 6x7 解決了它。
import numpy as np
import cv2
cap = cv2.VideoCapture('output.avi')
i=1
while(cap.isOpened()):
ret, img = cap.read()
print img
if img==None:#sale el error por que ya termino los frames del video
break #si no hay frames, terminarel programa
cv2.imshow('img2',img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
elif cv2.waitKey(1) & 0xFF==ord('p'):
cv2.imwrite('image'+str(i)+'.jpg',img)
i=i+1
cap.release()
cv2.destroyAllWindows()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.