我一直試圖通過使用2張圖像中手動選擇的對應點來計算matlab中的單應矩陣。這裏是我的代碼到目前爲止:用於在MATLAB中進行圖像拼接的Homography矩陣
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矩陣應該等於點矩陣,但它不是。我究竟做錯了什麼?
我的想法出了什麼問題? – NKN 2013-05-02 19:43:14
它不是什麼即時通訊尋找。不管怎樣,謝謝你 – 2013-05-03 18:32:34