Калибровка изображений для получения вида сверху для точек, лежащих на одной плоскости

Калибровка:

Я откалибровал камеру, используя этот набор инструментов зрения в Matlab. Я использовал изображения шахматной доски, чтобы сделать это. После калибровки я получаю камеру Params, которая содержит:

Camera Extrinsics
RotationMatrices: [3x3x18 double]
TranslationVectors: [18x3 double]

а также

 Camera Intrinsics
 IntrinsicMatrix: [3x3 double]
 FocalLength: [1.0446e+03 1.0428e+03]
 PrincipalPoint: [604.1474 359.7477]
 Skew: 3.5436

Цель: Я записал траектории движения некоторых объектов с помощью этой камеры. Каждый объект соответствует одной точке в кадре. Теперь я хочу спроектировать точки так, чтобы я получил вид сверху.

Обратите внимание, что все эти точки, которые я хочу преобразовать, находятся на одной плоскости.

например: [xcor_i, ycor_i]

-101.7000  -77.4040
-102.4200  -77.4040
КЛЮЧЕВОЙ МОМЕНТ: Эта плоскость перпендикулярна одному из изображений шахматной доски, используемых для калибровки. Для этого изображения (ниже) я знаю высоту происхождения шахматной доски от земли (193,040 см). И плоскость для проецирования точек параллельна земле и перпендикулярна этому изображению.

Код (Ref:https://stackoverflow.com/a/27260492/3646408 и ответим @Dima ниже):

function generate_homographic_matrix()
%% Calibrate camera
% Define images to process
path=['.' filesep 'Images' filesep];
list_imgs=dir([path '*.jpg']);
list_imgs_path=strcat(path,{list_imgs.name});

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

% Generate world coordinates of the corners of the squares
squareSize = 27;  % in units of 'mm'
worldPoints = generateCheckerboardPoints(boardSize, squareSize);

% Calibrate the camera
[cameraParams, imagesUsed, estimationErrors] = estimateCameraParameters(imagePoints, worldPoints, ...
    'EstimateSkew', true, 'EstimateTangentialDistortion', true, ...
    'NumRadialDistortionCoefficients', 3, 'WorldUnits', 'mm');
%% Compute homography for peripendicular plane to checkerboard
% Detect the checkerboard 
im=imread(['.' filesep 'Images' filesep 'exp_19.jpg']); %exp_19.jpg is the checkerboard orthogonal to the floor
[imagePoints, boardSize] = detectCheckerboardPoints(im);

% Compute rotation and translation of the camera.
[Rc, Tc] = extrinsics(imagePoints, worldPoints, cameraParams);

% Rc(rotation of the calibration view w.r.t the camera) = [x y z])
%then the floor has rotation Rf = [z x -y].(Normal vector of the floor goes up.)
Rf=[Rc(:,3),Rc(:,1),Rc(:,2)*-1];

% Translate it to the floor
H=452;%distance btw origin and floor
Fc = Rc * [0; H; 0];
Tc = Tc + Fc';

% Combine rotation and translation into one matrix:
Rf(3, :) = Tc;

% Compute the homography between the checkerboard and the image plane:
H = Rf * cameraParams.IntrinsicMatrix;

save('homographic_matrix.mat','H')
end
%% Transform points
function [x_transf,y_transf] =transform_points(xcor_i,ycor_i)
% creates a projective2D object and then transforms the points forward to
% get a top-view
% xcor_i and ycor_i are 1d vectors comprising of the x-coordinates and
% y-coordinates of trajectories. 
data=load('homographic_matrix.mat');
homo_matrix=data.H;
tform=projective2d(inv(homo_matrix));
[x_transf,y_transf] = transformPointsForward(tform,xcor_i,ycor_i);
end

Цитируя текст из OReilly Learning OpenCV Pg 412: «Как только у нас будет матрица гомографии и параметры высоты, которые мы хотим установить, мы можем затем снять шахматную доску и развернуть тележку, делая видео с высоты птичьего полета ... «Это то, чего я, по сути, хочу достичь.

Ответы на вопрос(2)

Ваш ответ на вопрос