本文对MATLAB鱼眼相机标定模型-Scaramuzza以及相关工具使用进行了介绍
The Computer Vision Toolbox contains calibration algorithms for the pinhole camera model and the fisheye camera model. You can use the fisheye model with cameras up to a field of view (FOV) of 195 degrees.
1.Matlab鱼眼相机模型-Scaramuzza
官方文档:Mathworks Fisheye Calibration Basics Document
1.1 世界坐标3D—>—相机坐标3D
$\begin{pmatrix} X_c\\ Y_c \\ Z_c \end{pmatrix}$为相机坐标系坐标,$R$为外参旋转矩阵,$\begin{pmatrix} X_w\\ Y_w \\ Z_w \end{pmatrix}$为世界坐标系坐标,$T$为外参平移向量
1.2 相机坐标3D—>—校正图像坐标2D
鱼眼相机模型的内参包括投影函数的多项式映射系数。对齐系数与传感器对齐以及从传感器平面到相机图像平面中的像素位置的转换有关。$u, v$是矫正后的图像坐标2D点,$a_0,a_2,a_3,a_4$是Scaramuzza模型[1]中描述的多项式系数($a_1$为0),$\lambda$是scalar factor。$\rho=\sqrt{u^2+v^2}$,是$u, v$相关的函数,仅与像素点与图像中心的距离有关
1.3 校正图像坐标2D—>—原始图像的像素坐标2D
内参也包括了拉伸和变形(仿射变换)。 拉伸矩阵补偿传感器到镜头的失准,失真向量调整图像平面的 (0,0) 位置。$\begin{pmatrix} c &d\\ e&1 \end{pmatrix}$为Stretch Matrix,$\begin{pmatrix} u’\\ v’ \end{pmatrix}$为原始图像的像素坐标,$\begin{pmatrix} u\\ v \end{pmatrix}$是理想的失真坐标,$\begin{pmatrix} c_x\\ c_y \end{pmatrix}$为Distortion Center
2 Matlab鱼眼相机标定参数使用Pipeline
2.1 Fisheye Model,根据鱼眼相机内参校正图像(数据预处理)
params = struct();
params.pattern_origin_height = 0; % Pattern is on ground
% 1.加载预先标定好的鱼眼相机内参
camera_intrinsics = {
'/home/kk/map_data/hongqi1_intrinsics/front_center_intrinsics.mat',...
};
intrinsics_mat = load(camera_intrinsics{1});
front_intrinsics = intrinsics_mat.front_center_cameraParams.Intrinsics;
% 2.得到校正后的虚拟内参以及校正图像
img = imread('/home/kk/Desktop/024010.jpg');
[J, cam_intrinsics] = undistortFisheyeImage(img, front_intrinsics, 'Output', 'full');
subplot(1,2,1);imshow(img);title('原始图像')
subplot(1,2,2);imshow(J);title('校正图像')
校正图像放大后的效果对比
1.2.2 Pinhole Model,校正图像的坐标转换(模型中)
在数据预处理过程中,原始图像已经经过鱼眼模型校正,校正后的图像可以近似为小孔成像模型。因此,可以利用校正图像的虚拟相机的内参去标定外参,由此得到转换过程中需要的全部坐标转换矩阵。
% 3.加载预先标定的2D-3D匹配点 img_points和world_points
load('./img_points.mat');
load('./world_points.mat');
% 4.求解鱼眼相机外参
[params.front_extri.pitch, params.front_extri.yaw, params.front_extri.roll, params.front_extri.x, params.front_extri.y, params.front_extri.height, params.front_extri.R, params.front_extri.T] = estimateMonoCameraParametersModify(front_intrinsics, ...
img_points,world_points, params.pattern_origin_height);
% 5.得到虚拟的小孔成像模型的内参
sensor = monoCamera(cam_intrinsics, params.front_extri.height, 'pitch', params.front_extri.pitch, 'yaw', params.front_extri.yaw, 'roll', params.front_extri.roll);
new_intrin = sensor.Intrinsics;
% 6.img_points从畸变图像转到校正图像
[size_1,size_2] = size(img_points);
new_img_points=[];
for n = 1:size_1
u_v = [img_points(n*2-1);img_points(n*2)];
u_v = (inv(front_intrinsics.StretchMatrix))*(u_v - front_intrinsics.DistortionCenter.');
new_img_points = [new_img_points;u_v.'];
end
% 7.得到虚拟的小孔成像模型的外参
[pitch, yaw, roll, x, y, height, R, T] = estimateMonoCameraParametersModify(new_intrin, ...
new_img_points,world_points, params.pattern_origin_height);
References
[1] Scaramuzza, D., A. Martinelli, and R. Siegwart. “A Toolbox for Easy Calibrating Omnidirectional Cameras.” _Proceedings to IEEE International Conference on Intelligent Robots and Systems, (IROS)_. Beijing, China, October 7–15, 2006.