使用python进行相机校准

时间:2014-03-07 13:17:02

标签: python opencv

我正在尝试使用棋盘方法校准我的拖车网络摄像头 但每次我执行opencv示例中提供的代码源 我收到了这条消息:

processing ../cpp\img1.jpg... chessboard not found
processing ../cpp\img2.jpg... chessboard not found
processing ../cpp\img3.jpg... chessboard not found
processing ../cpp\img4.jpg... chessboard not found
processing ../cpp\img5.jpg... chessboard not found

这是img1   http://i.stack.imgur.com/04b4U.jpg

好的,代码是opencv示例中的代码,它是cv2.FindChessboard()的一部分

 for fn in img_names:
    print 'processing %s...' % fn,
    img = cv2.imread(fn, 0)
    h, w = img.shape[:2]
    found, corners = cv2.findChessboardCorners(img, pattern_size)
    if found:
        term = ( cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_COUNT, 30, 0.1 )
        cv2.cornerSubPix(img, corners, (5, 5), (-1, -1), term)
    if debug_dir:
        vis = cv2.cvtColor(img, 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_points.append(corners.reshape(-1, 2))
    obj_points.append(pattern_points)

    print 'ok'

1 个答案:

答案 0 :(得分:1)

假设您的代码没问题,您的棋盘可能会出现问题。看看有关函数findChessboardCornerslink)的文档,最后有一条说明如下:

  

该功能需要空白区域(如方形粗边框,   电路板周围越宽越好,使检测更加稳健   在各种环境中。否则,如果没有边框和   背景很暗,外面的黑色方块不能分段   正确,所以方形分组和排序算法失败。

如果您查看this calibration tutorial中提供的图片,棋盘周围会有更多空白区域,这很重要

enter image description here

此外,它可能是一种印象,但看起来您的外部方块与其他方块的大小不同,这也很重要。