OpenCV:相机标定-getOptimalNewCameraMatrix函数

相机标定后,对采集的图像进行畸变矫正,代码如下:

if( !capture.isOpened() && showUndistorted )
    {
        Mat view, rview, map1, map2;
        initUndistortRectifyMap(cameraMatrix, distCoeffs, Mat(),
                                getOptimalNewCameraMatrix(cameraMatrix, distCoeffs, imageSize, 1, imageSize, 0),
                                imageSize, CV_16SC2, map1, map2);

        for( i = 0; i < (int)imageList.size(); i++ )
        {
            view = imread(imageList[i], 1);
            if(!view.data)
                continue;
            //undistort( view, rview, cameraMatrix, distCoeffs, cameraMatrix );
            remap(view, rview, map1, map2, INTER_LINEAR);
            imshow("Image View", rview);
            int c = 0xff & waitKey();
            if( (c & 255) == 27 || c == 'q' || c == 'Q' )
                break;
        }
    }

getOptimalNewCameraMatrix是调节视场大小,为1时视场大小不变,小于1时缩放视场;

畸变矫正图像如下:

上图是去畸变之后的图像,径向畸变已经移除,但为什么会出现这个情况?

这是由于边缘的径向畸变比中心的径向畸变严重;

Consider the image above. It has been undistorted. Lines that are straight in 3D space are now straight in the 2D projection (the 2D image). Radial distortion has been removed. But what's up with the "four pointed star" shape? This is because in order to correct for radial distortion, pixels that are further away from the center of distortion must get pushed more than pixels closer to the center of distortion. See the picture below:

The red dots represent pixel locations before undistorting: they follow a regular grid. But the radial distortion model says that as one moves away from center of distortion, the distortion gets worse. It is called a radialdistortion model because this is a function of the size of the radius of a circle centered around the center of distortion. The heads of the blue vectors represent where the red pixels will get undistorted to. Since the original image is a rectangle, the points toward the corners have the highest radius, and they must get pushed out more. But if you want to see every pixel from the original image, this means you will have the black "hills" on the sides of the undistorted image. If you don't want to see these black hills, set alpha to 0. If you do want to see these black hills, set alpha to 1. If you want to see the black hills, but you want them to be smaller, set alpha to 0.5. You get the picture.

 

参考文章:

1. https://answers.opencv.org/question/101398/what-does-the-getoptimalnewcameramatrix-function-does/

 

 

  • 5
    点赞
  • 31
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值