我试图根据opencv示例中给出的示例校准我的web-cam,但是当我运行这里提供的代码时:
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
型
这个错误是什么意思?怎么解决呢?
6条答案
按热度按时间qf9go6mv1#
该错误表示作为参数提供的向量之一为空。
该函数有一个Assert,如果不是所有条件都满足,则阻止您使用它。这次它检查是否有足够的图像点(
nimages > 0
必须为真)。kgsdhlau2#
重新检查函数“cv2.findChessboardCorners(image,(nx,ny))/ cv2.drawChessboardCorners(image,pattern_size)”的nx和ny(pattern_size)的值,这应该是棋盘中内角行和列的数量。对我很有效。
k0pti3hp3#
我知道我来晚了,但我希望这能帮助到其他人。替换以下行:
字符串
与:
型
jvidinwx4#
在我的情况下,我没有使用一个足够大的棋盘在样本图片。打印7x10棋盘而不是6x7解决了这个问题。
1aaf6o9v5#
试着数棋盘的内角。在我的情况下,它是8乘6。这很好用。stackoverflow.com/questions/27348139
ki1q1bka6#
字符串