0. 说明
鱼眼相机校正和普通相机校正流程基于相同,
将修改标定函数和参数即可。
1. 上代码,含详细注释与区别
import cv2
import numpy as np
import glob
def calib(inter_corner_shape, size_per_grid, path):
# 获取棋盘格角点个数
w, h = inter_corner_shape
# 世界坐标维度为三,与角点维度对齐
# 普通相机校正中世界坐标比角点坐标少一个维,在鱼眼相机校正中少一维会报错
cp_int = np.zeros((1, w * h, 3), np.float32)
cp_int[0, :, :2] = np.mgrid[0:w, 0:h].T.reshape(-1, 2).astype(np.float64)
cp_world = cp_int * size_per_grid
# 检测亚像素角点
subpix_criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.1)
# 标定方法
calibration_flags = cv2.fisheye.CALIB_RECOMPUTE_EXTRINSIC + cv2.fisheye.CALIB_CHECK_COND + cv2.fisheye.CALIB_FIX_SKEW
# 图像尺寸
img_shape = None
# 世界坐标
obj_points = []
# 角点坐标
img_points = []
# 获取图片
images = glob.glob(path + '/*.jpg')
|