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]];

Draw a checkerboard

initialize axes...

clf; hold on;
axis([0 640 0 480]);

then draw 40x40 squares at y=-10 (remember that camera is at origin)

y=-10;
for i=-20:20
    for j=-20:20
        A=[i,  y,j  ,1]';
        B=[i+1,y,j  ,1]';
        C=[i+1,y,j+1,1]';
        D=[i,  y,j+1,1]';
        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([a(1) b(1) c(1) d(1) a(1)],...
             [a(2) b(2) c(2) d(2) a(2)],...
             'LineWidth', 2);
    end
end

Some questions...

- why do you see a part of the checkerboard on the top? - how could you avoid it?

Some extensions:

try to change the camera parameters and see the results!

Animate the checkerboard!

(run the code below) note that you can visualize the effect of changing camera parameters!

% %% Animate the checkerboard
% for y=linspace(0,-30,100)
%
% clf; hold on;
% axis([0 640 0 480]);
%
% for i=-20:20
%     for j=-20:20
%         A=[i,  y,j  ,1]';
%         B=[i+1,y,j  ,1]';
%         C=[i+1,y,j+1,1]';
%         D=[i,  y,j+1,1]';
%         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([a(1) b(1) c(1) d(1) a(1)],...
%              [a(2) b(2) c(2) d(2) a(2)],...
%              'LineWidth', 2);
%     end
% end
% drawnow;
% end