美文网首页
OpenCV:鱼眼相机去畸变=图像去畸变+点去畸变

OpenCV:鱼眼相机去畸变=图像去畸变+点去畸变

作者: AI秘籍 | 来源:发表于2020-04-17 19:49 被阅读0次

官网:https://docs.opencv.org/3.4/db/d58/group__calib3d__fisheye.html

鱼眼相机去畸变,即图像矫正,分为整幅图像去畸变和点去畸变.

1.去畸变函数

先来看一下鱼眼相机的去畸变函数.
已知鱼眼相机的内参矩阵和畸变系数


image.png

step1.先估计新的相机内参矩阵
这个新的相机内参矩阵是去畸变后的,图像矫正后的.
Estimates new camera matrix for undistortion or rectification.


image.png
image.png

P New camera matrix (3x3) or new projection matrix (3x4)
balance Sets the new focal length in range between the min focal length and the max focal
length. Balance is in range of [0, 1].

step2. initUndistortRectifyMap()
这个函数的作用是初始化畸变矫正矩阵,
将KDRP转换为map1和map2.
之后就可以通过remap函数计算无畸变图像了.


image.png
image.png

这里有个问题,为什么要把KDRP转换为map1,map2之后在使用remap矫正?
https://docs.opencv.org/master/d4/d94/tutorial_camera_calibration.html
这里有个解释.
之所以扩展undistort函数为initUndistortRectifyMap,是为了提高算法运行速度.

image.png

step3.remap()图像矫正函数

// 图像去畸变
cv::Mat cam_im = imread("1.png");
cv::Mat correct_image;
 cv::remap(cam_im, correct_image, map1, map2, cv::INTER_LINEAR);

(4)undistortImage()函数
这个函数是fisheye::initUndistortRectifyMap和remap函数的合并
Knew是畸变图像的相机内参矩阵,默认是单位阵.

image.png
image.png

(5)undistortPoints是点去畸变函数


image.png

程序

//已知相机内参和畸变系数
//step1.估计新矩阵
cv::Mat newCamMat;
// 估计新的相机内参矩阵,无畸变后的
cv::fisheye::estimateNewCameraMatrixForUndistortRectify(
    camera_intrinsic_matrix, distort_coeff_matrix, img_size,
    cv::Matx33d::eye(), newCamMat, 1);
//step2.计算map1,map2
cv::Mat map1, map2;
cv::fisheye::initUndistortRectifyMap(
        camera_intrinsic_matrix, 
        distort_coeff_matrix, 
    cv::Matx33d::eye(), newCamMat, img_size,
    CV_16SC2, map1, map2);

// step3.remap图像去畸变
cv::Mat cam_im = imread("1.png");
cv::Mat correct_image;
cv::remap(cam_im, correct_image, map1, map2, cv::INTER_LINEAR);

//step4. undistortImage图像去畸变
cv::Mat undistort_im;
cv::fisheye::undistortImage(
    cam_im,undistort_im,
    camera_intrinsic_matrix,
    distort_coeff_matrix,
    newCamMat,
    cam_im.size());
//step5.比较一下这两个图像是否一直
cv::Mat substrct_im;
cv::subtract(undistort_im,correct_image,substrct_im);
cv::imwrite("substrct_im.jpg",substrct_im);

//step6.undistortPoints图像点去畸变
std::vector<cv::Point2f> src_pts{ cv::Point2f(500,500)};
std::vector<cv::Point2f> dst_pts;
cv::fisheye::undistortPoints(
    src_pts,dst_pts,
       camera_intrinsic_matrix,
    distort_coeff_matrix,
    cv::noArray(),
    newCamMat);
cout<<"dst_pts= "<<dst_pts[0]<<endl;

相减结果

说明这两个函数结果一致.

image.png

去畸变点的坐标为(725,514)和去畸变图像中一致.

参考:

  1. https://docs.opencv.org/3.4/db/d58/group__calib3d__fisheye.html
  2. https://blog.csdn.net/baidu_38172402/article/details/89597692
  3. https://blog.csdn.net/jonathanzh/article/details/104418758
  4. https://docs.opencv.org/master/d4/d94/tutorial_camera_calibration.html

相关文章

  • OpenCV:鱼眼相机去畸变=图像去畸变+点去畸变

    官网:https://docs.opencv.org/3.4/db/d58/group__calib3d__fis...

  • 摄像头标定 Python + OpenCV

    〇、基础 一些单孔摄像机(照相机)会给图像带来很多畸变。畸变主要有两种:径向畸变和切向畸变。如下图所示,用红色直线...

  • 相机标定

    透镜畸变 径向畸变:远离透镜中心的光线弯曲比靠近中心的严重切向畸变:透镜与图像平面不平行而产生 畸变矫正 对于径向...

  • 无人驾驶小课堂 - OpenCV 中的图像校正

    1. 常见的图片畸变 无人驾驶摄像头/照相机镜头往往会有两种形式的图像变形,径向畸变(Radial Distort...

  • 径向畸变和反射模型

    径向畸变:图像的点坐标沿着与图像中心的径向距离成比例地靠近和远离,靠近图像中心称为桶形畸变,远离图像中心称为枕形畸...

  • 相机模型

    题目描述:相机模型有哪些参数,写出三维空间点到图像坐标投影公式。镜头畸变系数有哪几种,对应畸变矫正的公式表达?答案...

  • OpenCV-Python教程:46.摄像头标定

    基础 今天的针孔摄像头对图像做了很多扭曲,两个主要的扭曲是径向畸变和切向畸变。 由于径向畸变,直线会显示成曲线,当...

  • ORB-SLAM2代码笔记(二):Frame

    Frame 成员变量: ORB特征字典——用于重定位 ORB特征提取句柄 时间戳 相机内参 去畸变参数 判断远近点...

  • 关于opencv图像畸变矫正

    本文通过摄像头参数(fx,fy,cx,cy,k1,k2,p1,p2,p3(标定得到))去矫正摄像头拍出来的图像畸变...

  • OpenCV 不同畸变校正函数的使用说明

    1. 各畸变校正函数说明 OpenCV 针对不同的使用场景提供了几个不同用法的畸变校正函数。 主要有以下几种: i...

网友评论

      本文标题:OpenCV:鱼眼相机去畸变=图像去畸变+点去畸变

      本文链接:https://www.haomeiwen.com/subject/cfybmhtx.html