使用棋盘校准Sony RX1相机,但无法检测到角落

时间:2018-08-23 07:14:47

标签: python-3.x pycharm camera-calibration opencv3.1

我是图像处理的新手,我需要使用python + opencv来校准我的Sony RX1相机(照片尺寸7952 * 5304像素)。

问题是,如果我不使用以下命令调整棋盘照片的大小 img = cv2.resize(img, (int(h / 4), int(w / 4))interpolation=cv2.INTER_AREA)或 缩小照片

findChessboardCorners在某些照片中找不到角,当我调整照片大小时,一切都很好。

我想知道它是怎么来的?

这是我的相机校准代码(python 3.6 + opencv 3.4和pycharm作为IDE)

criteria = (cv2.TERM_CRITERIA_EPS + cv2.TermCriteria_MAX_ITER, 30, 0.001)
pattern_size = (9, 6)
objp = np.zeros((6 * 9, 3), np.float32)
objp[:, :2] = np.mgrid[0:9, 0:6].T.reshape(-1, 2)
objpoints = []
imgpoints = []
# get all image filepaths
images = glob.glob(filename + '/*')
h, w = cv2.imread(images[0]).shape[:2]

for fname in images:
    img = cv2.imread(fname)
    print('load image \n', fname)
    # img = cv2.resize(img, (int(h / 4), int(w / 4)), 
                       interpolation=cv2.INTER_AREA)
    if img is None:
        print("Failed to load", filename)
        return None
    if img.ndim == 3:
        gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    else:
        gray = img

    ret, corners = cv2.findChessboardCorners(gray, pattern_size,                                               
                                             cv2.CALIB_CB_ADAPTIVE_THRESH +
                                             cv2.CALIB_CB_FAST_CHECK +                                                  
                                             cv2.CALIB_CB_NORMALIZE_IMAGE)
    if ret:
        objpoints.append(objp)
        corners2 = cv2.cornerSubPix(gray, corners, (5, 5), (-1, -1), 
                                    criteria)
        imgpoints.append(corners2)
    else:
        print('chessboard not found')
        return None
ret, camera_matrix, dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, 
                                          imgpoints, (h, w), None, None)

0 个答案:

没有答案