如何找到两组点之间的径向畸变系数?

How to find radial distortion coefficients between two sets of points?

标题更改自:特定 transformation/distortion 使用棋盘坐标的图像

我有两张棋盘格图片。其中一个比另一个稍微扭曲。我认为这是一种 "barrel" 失真。我正在尝试计算径向畸变参数(或生成相机参数),以便使其中一张图像看起来像另一张图像,以便棋盘角对齐。

这是二值未失真图像,其角点绘制为蓝色 o,我们需要扭曲图像以绘制为红色 o 的角点参考坐标。

大部分失真发生在边缘和角落周围。我相信这是一种径向畸变。如何找到表示棋盘角的两组坐标之间的径向畸变系数?

Link 到图像 A(未失真):http://imgur.com/rg4PNvp

Link 到图像 B(失真):http://imgur.com/a/BIvid

我需要将图像 B 中的棋盘转换为使其角与图像 A 中的角对齐。

我尝试修改 MATLAB Camera Calibration 应用程序生成的脚本(link). I changed the world points that would be used to estimate camera parameters to equal my world points (corners) from Image A. However, this wasn't successful. The code I tried is can be seen in this pastebin: https://pastebin.com/D0StCb0p 我在 imageFileNames 中使用了相同的图像,因为 estimateCameraParameters 需要至少 2 组坐标。

代码:

% Define images to process
imageFileNames = {'C:\Users\asavelyev\Pictures\checkerB.tif',...
    'C:\Users\asavelyev\Pictures\checkerB.tif',...
    };

% Detect checkerboards in images
[imagePoints, boardSize, imagesUsed] = detectCheckerboardPoints(imageFileNames);
imageFileNames = imageFileNames(imagesUsed);

% Read the first image to obtain image size
originalImage = imread(imageFileNames{1});
[mrows, ncols, ~] = size(originalImage);

% AS: change these worldPoints to points of RGB image...
% Generate world coordinates of the corners of the squares
worldPoints = detectCheckerboardPoints('C:\Users\asavelyev\Pictures\checkerA.tif');

% Calibrate the camera
[cameraParams, imagesUsed, estimationErrors] = estimateCameraParameters(imagePoints, worldPoints, ...
    'EstimateSkew', false, 'EstimateTangentialDistortion', false, ...
    'NumRadialDistortionCoefficients', 2, 'WorldUnits', 'millimeters', ...
    'InitialIntrinsicMatrix', [], 'InitialRadialDistortion', [], ...
    'ImageSize', [mrows, ncols]);

% For example, you can use the calibration data to remove effects of lens distortion.
undistortedImage = undistortImage(originalImage, cameraParams);

这是通过使用 Mathematics Whosebug 中的 post 解决的:https://math.stackexchange.com/questions/302093/how-to-calculate-the-lens-distortion-coefficients-with-a-known-displacement-vect

我监督的主要问题是用于计算径向失真中使用的 K 系数的数据点的归一化。

这是我为查找这些系数而编写的 MATLAB 脚本:

% input images should be black and white checkerboards already thresholded into a binary image
% output image are the K coefficients used in radial distortion

function K = CalculateRadialDistortion(DistortedImg, UndistortedImg)

    distortedCorners = detectCheckerboardPoints(DistortedImg);
    undistortedCorners = detectCheckerboardPoints(UndistortedImg);

    % normalize data
    X1 = distortedCorners(:,1) - size(DistortedImg, 2)/2;
    Y1 = distortedCorners(:,2) - size(DistortedImg, 1)/2;

    X1p = undistortedCorners(:,1) - size(DistortedImg, 2)/2;
    Y1p = undistortedCorners(:,2) - size(DistortedImg, 1)/2;

    % X1p = (1+k1*r^2 + k2*r^4)X1 where r^2 = X1^2 + Y1^2

    Rsq =  X1.^2 + Y1.^2;
    Rquad = Rsq.^2;

    Rsqd = cat(1, Rsq, Rsq);
    Rquadd = cat(1, Rquad, Rquad);

    R = cat(2, Rsqd, Rquadd);

    X1poX1 = X1p ./ X1;
    X1poX1 = X1poX1 - 1;

    Y1poY1 = Y1p ./ Y1;
    Y1poY1 = Y1poY1 - 1;

    X1Y1 = cat(1, X1poX1, Y1poY1);

    K = linsolve(R, X1Y1);

end