OpenCV下的无标定校正(stereoRectifyUncalibrated)
文章目录
1. 杂话
咱们在之前的帖子里面讲了一些比较常规的标定和校正OpenCV下的单目标定,双目标定与立体校正(calibrateCamera, stereoCalibrate and stereoRectify),但是,如果说两个相机之间的转角比较大,那么可能并不适合用双目标定+立体校正的步骤来做,参考这个贴子立体校正失效的情况,所以为了解决这个问题,今天咱们就来说说如何使用非标定的校正函数:
对了,我使用的数据和完整的代码在这里:Repo : Calibrate-and-Rectify
2. 无标定校正
2.1 先看代码
import cv2
import numpy as np
import glob
import matplotlib.pyplot as plt
from PIL import Image
c1_images_names = sorted(glob.glob('demo/left*.jpg'))
c2_images_names = sorted(glob.glob('demo/right*.jpg'))
c1_images = []
c2_images = []
for im1, im2 in zip(c1_images_names, c2_images_names):
_im = cv2.imread(im1, 1)
c1_images.append(_im)
_im = cv2.imread(im2, 1)
c2_images.append(_im)
def find_corners(image_names):
images = []
for imname in image_names:
im = cv2.imread(imname, 1)
images.append(im)
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001)
rows = 6 #number of checkerboard rows.
columns = 9 #number of checkerboard columns.
#coordinates of squares in the checkerboard world space
objp = np.zeros((rows*columns,3), np.float32)
objp[:,:2] = np.mgrid[0:rows,0:columns].T.reshape(-1,2)
#frame dimensions. Frames should be the same size.
width = images[0].shape[1]
height = images[