gpt4 book ai didi

matlab - 校准图像以获得位于同一平面上的点的俯 View

转载 作者:太空宇宙 更新时间:2023-11-03 19:20:54 27 4
gpt4 key购买 nike

校准:

我已经在 Matlab 中使用这个视觉工具箱校准了相机。我使用棋盘图像来这样做。校准后我得到了 cameraParams其中包含:

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

目标:我用这台相机记录了一些运动物体的轨迹。每个对象对应于帧中的单个点。现在,我想投影这些点,以便获得俯 View 。

  1. 请注意,我希望变换的所有这些点都在同一平面上。

    例如:[xcor_i,ycor_i]

    -101.7000  -77.4040
    -102.4200 -77.4040
  2. KEYPOINT:该平面垂直于用于校准的棋盘图像之一。对于该图像(下图),我知道棋盘离地面的原点高度(193.040 厘米)。并且投影点的平面平行于地面并垂直于此图像。

Figure 1

代码(引用: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 中的文字:“一旦我们有了单应矩阵和我们希望的高度参数集,我们就可以然后拆下棋盘,开着小车转一圈,做一个鸟瞰视频道的……”这是我本质上希望实现的目标。

最佳答案

阿布舍克

我不完全明白你想做什么。您的点在一个平面上吗?您是否正在尝试创建该平面的鸟瞰图?

如果是这样,那么您需要知道外部参数 R 和 t,它们描述了该平面与相机之间的关系。获得 R 和 t 的一种方法是在平面上放置一个棋盘,然后使用 extrinsics 函数。

之后,您可以按照 question you cited 中的说明进行操作得到单应性。一旦你有了单应性,你就可以创建一个 projective2D 对象,并使用它的 transformPointsForward 方法来转换你的点。

关于matlab - 校准图像以获得位于同一平面上的点的俯 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34461821/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com