我一直在尝试通过使用从 2 个图像中手动选择的对应点来计算 matlab 中的单应矩阵。到目前为止,这是我的代码:
spoints = [330.756756756757,923.310810810811; %points from source image
335.945945945946,1016.71621621622;
495.081081081081,771.094594594595;
498.540540540540,933.689189189189];
dpoints = [310.000000000000,477.040540540540; %points from destination image
320.378378378378,558.337837837838;
462.216216216216,319.635135135135;
469.135135135135,471.851351351351];
%/////////////homography matrix///////////////////
n = size(spoints, 1);
A = zeros(n*2,8);
b = zeros(n*2,1);
j=1;
for i=1:n
A(j,:)=[dpoints(i,1) dpoints(i,2) 1 0 0 0 -spoints(i,1)*dpoints(i,1) - spoints(i,1)*dpoints(i,2)];
b(j,1)=spoints(i,1);
j=j+1;
A(j,:)=[0 0 0 dpoints(i,1) dpoints(i,2) 1 -spoints(i,2)*dpoints(i,1) -spoints(i,2)*dpoints(i,2)];
b(j,1)=spoints(i,2);
j=j+1;
end
x = (A\b);
H = [x(1,1) x(2,1) x(3,1);
x(4,1) x(5,1) x(6,1);
x(7,1) x(8,1) 1];
这没有给出正确的 H 矩阵。我通过
bla = zeros(4,3);
bla(1,:,:)=H*[dpoints(1,:),1]';
bla(2,:,:)=H*[dpoints(2,:),1]';
bla(3,:,:)=H*[dpoints(3,:),1]';
bla(4,:,:)=H*[dpoints(4,:),1]';
bla 矩阵应该等于点矩阵,但不是。我究竟做错了什么?