Contents
Build a simple camera matrix
(assuming a 640x480 sensor)
K=[240 0 320; 0 240 240; 0 0 1]; P=[K,[0;0;0]];
Consider several points in homogeneous coordinates
A=[+1,+1,1,1]';
B=[+1,+1,2,1]';
C=[+1,+1,3,1]';
%D=[+1,+1,10000,1]'; % A point at the infinity! (try it)
D=[+1,+1,4,1]';
... and project them
a=P*A; b=P*B; c=P*C; d=P*D; a=a/a(3); b=b/b(3); c=c/c(3); d=d/d(3);
Plot results
plot(a(1),a(2),'o', 'MarkerEdgeColor','k',... 'MarkerFaceColor','g',... 'MarkerSize',10); hold on; plot(b(1),b(2),'o', 'MarkerEdgeColor','k',... 'MarkerFaceColor','g',... 'MarkerSize',10); plot(c(1),c(2),'o', 'MarkerEdgeColor','k',... 'MarkerFaceColor','g',... 'MarkerSize',10); plot(d(1),d(2),'o', 'MarkerEdgeColor','k',... 'MarkerFaceColor','g',... 'MarkerSize',10); axis([0 640 0 480]); drawnow;
Verify cross ratio properties:
first compute distances in real world ...
AB=norm(A-B); AC=norm(A-C); AD=norm(A-D); BC=norm(B-C); BD=norm(B-D); CD=norm(C-D);
... then distances in the image.
ab=norm(a-b); ac=norm(a-c); ad=norm(a-d); bc=norm(b-c); bd=norm(b-d); cd=norm(c-d);
now check that the cross ratio is invariant to projection
(bc/ac)/(bd/ad) (BC/AC)/(BD/AD)
ans =
0.7500
ans =
0.7500
Animate the moving point!
(run the code below)
% clf; hold on; % axis([0 640 0 480]); % for t=linspace(0,10,300) % A=[1-t,1,t,1]'; % a=P*A; % a=a/a(3); % B=[1-t,-1,t,1]'; % b=P*B; % b=b/b(3); % % plot(a(1),a(2),'o', 'MarkerEdgeColor','k',... % 'MarkerFaceColor','g',... % 'MarkerSize',10); % plot(b(1),b(2),'o', 'MarkerEdgeColor','k',... % 'MarkerFaceColor','g',... % 'MarkerSize',10); % drawnow; % end % % % what happens when t=linspace(20,-20,1200) ? % % what happens when A=[+1+t,+1,t,1]'; % %