Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从已知的内在和外在参数在Matlab中进行透视校正?_Matlab_Computer Vision_Matlab Cvst_Extrinsic Parameters - Fatal编程技术网

如何从已知的内在和外在参数在Matlab中进行透视校正?

如何从已知的内在和外在参数在Matlab中进行透视校正?,matlab,computer-vision,matlab-cvst,extrinsic-parameters,Matlab,Computer Vision,Matlab Cvst,Extrinsic Parameters,我正在使用Matlab进行摄像机校准。我有所有的照相机 校准程序中的参数。当我使用一个新的图像时 在校准集中,我可以得到它的转换方程,例如。 Xc=R*X+T,其中X是校准装置(平面)的三维点 “世界”帧,以及Xc在摄影机帧中的坐标。换句话说 换句话说,我拥有一切(外在和内在参数) 我想做的是对这张图像进行透视校正 i、 e.我希望它移除任何透视图并查看校准装置 不失真(它是一个棋盘) Matlab新的计算机视觉工具箱中有一个对象,它可以在一个物体上执行透视变换 图像,给定一个3X3矩阵H。问题

我正在使用Matlab进行摄像机校准。我有所有的照相机 校准程序中的参数。当我使用一个新的图像时 在校准集中,我可以得到它的转换方程,例如。 Xc=R*X+T,其中X是校准装置(平面)的三维点 “世界”帧,以及Xc在摄影机帧中的坐标。换句话说 换句话说,我拥有一切(外在和内在参数)

我想做的是对这张图像进行透视校正 i、 e.我希望它移除任何透视图并查看校准装置 不失真(它是一个棋盘)

Matlab新的计算机视觉工具箱中有一个对象,它可以在一个物体上执行透视变换 图像,给定一个3X3矩阵H。问题是,我不能计算这个 从已知的内在和外在参数矩阵

方法1: 在相机校准工具箱中,您应该注意到工作区中棋盘格的每个图像都有一个H矩阵。我还不熟悉计算机视觉工具箱,但也许这就是你的功能所需要的矩阵。H的计算方法似乎是这样的:

KK = [fc(1) fc(1)*alpha_c cc(1);0 fc(2) cc(2); 0 0 1];
H = KK * [R(:,1) R(:,2) Tc]; % where R is your extrinsic rotation matrix and Tc the translation matrix
H = H / H(3,3);
方法2: 如果计算机视觉工具箱函数不适用于您,那么为了找到图像的预期投影,我使用了如下函数:

[X, Y] = meshgrid(0:size(I,2)-1, 0:size(I,1)-1);
im_coord = [X(:), Y(:), ones(prod(size(I_1)))]';
% Insert projection here for X and Y to XI and YI
ZI = interp2(X,Y,Z,XI,YI);

不久前,我在一个项目中使用了前瞻性预测,我认为需要使用齐次坐标。我认为我发现维基百科的文章非常有用。

对于所有几个月后仍然对此感兴趣的人,我已经设法使用Kovesi的代码()获得了正确的单应矩阵,尤其是homography2d.m函数。但是,您需要装备四个角的像素值。如果相机是固定的,那么你需要这样做一次。请参见下面的示例代码:

%get corner pixel coords from base image
p1=[33;150;1];
p2=[316;136;1];
p3=[274;22;1];
p4=[63;34;1];
por=[p1 p2 p3 p4];
por=[0 1 0;1 0 0;0 0 1]*por;    %swap x-y <--------------------

%calculate target image coordinates in world frame
% rig is 9x7 (X,Y) with 27.5mm box edges
XXw=[[0;0;0] [0;27.5*9;0] [27.5*7;27.5*9;0] [27.5*7;0;0]];
Rtarget=[0 1 0;1 0 0;0 0 -1]; %Rotation matrix of target camera (vertical pose)
XXc=Rtarget*XXw+Tc_ext*ones(1,4); %go from world frame to camera frame
xn=XXc./[XXc(3,:);XXc(3,:);XXc(3,:)]; %calculate normalized coords
xpp=KK*xn;  %calculate target pixel coords

% get homography matrix from original to target image
HH=homography2d(por,xpp);
%do perspective transformation to validate homography
pnew=HH*por./[HH(3,:)*por;HH(3,:)*por;HH(3,:)*por]; 

我也想知道这个问题的答案。我觉得这篇文章中可能有一些线索:,尽管我还没有时间阅读和消化它。
% corner coords in pixels
p1=[33;150;1];
p2=[316;136;1];
p3=[274;22;1];
p4=[63;34;1];
pmat=[p1 p2 p3 p4];
pmat=[0 1 0;1 0 0;0 0 1]*pmat; %swap x-y

R=[0 1 0;1 0 0;0 0 1];  %rotation matrix of final camera pose
Rmat=Rc_ext'*R;  %rotation from original pose to final pose
H=KK*Rmat*inv_KK; %homography matrix
pnew=H*pmat./[H(3,:)*pmat;H(3,:)*pmat;H(3,:)*pmat]; %do perspective transformation

H2=[0 1 0;-1 0 0;0 0 1]*H;  %swap x-y in the homography matrix to apply in image