普通相机模型
无畸变时相机模型的状态:
有畸变时的状态:
简单来讲就是获得地图点在归一化相机平面上的坐标[x',y']之后,进行加畸变操作,k1,k2,k3,k4,k5,k6都是径向畸变参数, 而p1,p2都是切向畸变参数,s1,s2...是棱镜参数,一般不常用;这里对应到的去畸变代码是:
int flags = 0;
flags |= cv::CALIB_FIX_K3;
cv::Mat intrinsic_matrix= cv::Mat::eye(3,3,CV_32FC1);
cv::Mat distortion_coeffs, rotation_vectors, translation_vectors;
cv::calibrateCamera(object_Points, corners_Seq, image_size, intrinsic_matrix,distortion_coeffs, rotation_vectors, translation_vectors,flags);
而在distortion_coeffs中,各畸变参数分别如下: k1,k2,p1,p2,k3...
径向畸变又细分为桶形畸变和枕形畸变,桶形畸变图像普遍往外鼓, 对应的畸变公式一定是单调函数且是双射的,如果非单调,通常是标定错误;错误的标定结果可能使得图像的中心部分看起来相对不错,但是很难应用在AR/SFM问题上,具体的原因可以参见#issue15992
鱼眼相机模型
两者的区别是在得到归一化相机平面的坐标之后,一个直接进行切向畸变和径向畸变的计算,另一个直接进行利用角度theta计算从相机坐标到虚拟投影球面的坐标
其对应的在opencv中的代码是:
cv::Matx33d intrinsic_matrix(1,0,0,0,1,0,0,0,1); /***** 摄像机内参数矩阵 ****/
cv::Vec4d distortion_coeffs; /* 摄像机的4个畸变系数:k1,k2,k3,k4*/
std::vector<cv::Vec3d> rotation_vectors; /* 每幅图像的旋转向量 */
std::vector<cv::Vec3d> translation_vectors; /* 每幅图像的平移向量 */
int flags = 0;
flags |= cv::fisheye::CALIB_RECOMPUTE_EXTRINSIC;
//flags |= cv::fisheye::CALIB_CHECK_COND;
flags |= cv::fisheye::CALIB_FIX_SKEW;
fisheye::calibrate(object_Points, corners_Seq, image_size, intrinsic_matrix,
distortion_coeffs, rotation_vectors, translation_vectors,
flags, cv::TermCriteria(3, 20, 1e-6));
有了对应的标定公式,就有对应的去畸变公式, 如下:
鱼眼相机模型对应的代码及问题
fisheye::initUndistortRectifyMap(intrinsic_matrix, distortion_coeffs, R,intrinsic_matrix,cv::Size(Width,Height), CV_32FC1, mapx, mapy);
用错数据时会出现的问题assertion failed (k.size() == size(3, 3) && (d.empty() || d.total() == 4)) in initundistortrectifyMap(), 错误的原因是K不是3x3,或者D的size不是1x4;
普通相机模型对应的代码及问题
cv::initUndistortRectifyMap(intrinsic_matrix, distortion_coeffs, R,intrinsic_matrix,cv::Size(Width,Height), CV_32FC1, mapx, mapy);
同时,issue15992中提到了一些标定问题的来源:
- not using a flat chessboard pattern, often a paper sheet is used and not glued correctly
- blurry images
- too few images, too many images
- acquired images are too similar, does not cover the whole image space, ...
以及一些比较好的建议:
如有疑问,欢迎交流: wx: baobaohaha_ 欢迎对SLAM有兴趣的小伙伴一起交流学习~~
REF:
普通畸变相机模型:https://mp.csdn.net/editor/html/109991695
鱼眼畸变相机模型:https://docs.opencv.org/3.1.0/db/d58/group__calib3d__fisheye.html#gad626a78de2b1dae7489e152a5a5a89e1