% function process_pic( n )
%UNTITLED2 Summary of this function goes here
%   Detailed explanation goes here

n = 24;
load filelist
load script2
filename = char(files(n));
rgb = imread(filename);
imshow(rgb);

pts = ginput();

hold on
plot(pts(1:2,1),pts(1:2,2),'y','LineWidth',2);
plot(pts(3:4,1),pts(3:4,2),'y','LineWidth',2);
plot(pts(4:end,1),pts(4:end,2),'wx');
hold off
Warning: Image is too big to fit on screen; displaying at 50% 
out = imtransform(rgb,tf2,'Xdata',[-1000 3000],'Ydata',[-6000 0]);
imshow(out);

[xpts ypts] = tformfwd(tf2,pts(:,1),pts(:,2));
hold on
xv = xpts+1000;
yv = ypts+6000;
plot(xv(1:2),yv(1:2),'m','LineWidth',2);
plot(xv(3:4),yv(3:4),'y','LineWidth',2);
hold off
theta  = cross2d([xv(1:2) yv(1:2)],[0 0; 0 1]);
fprintf('camera orientation angle %g deg\n',theta);

xs = xpts/scale;
ys = -ypts/scale;
phi = theta*pi/180;
cs = cos(phi);
ss = sin(phi);
xp = cs*xs-ss*ys;
yp = ss*xs+cs*ys;


cam = [0 0; -ss cs]*3;


plot(xp(1:2),yp(1:2),'y','LineWidth',2);
axis equal
grid on
hold on
plot(cam(1,1),cam(1,2),'ko');
plot(cam(:,1),cam(:,2),'k','LineWidth',2);
plot(xp(3:4),yp(3:4),'y','LineWidth',2);
plot(xp(4:end),yp(4:end),'kx');
hold off
eval(['save cam_' int2str(n) ' cam theta xp yp pts']);
camera orientation angle 12.0583 deg