script4

clear
close all
load filelist
load script2
n=12;
filename = char(files(n));
rgb = imread(filename);
imshow(rgb);

%pts = ginput();
load hall12

hold on
plot(pts(1:2,1),pts(1:2,2),'y','LineWidth',2);
plot([pts(1,1) pts(3,1)],[pts(1,2) pts(3,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 33% 
load script2
out = imtransform(rgb,tf2,'Xdata',[-1000 1000],'Ydata',[-3000 0]);
imshow(out);
[xpts ypts] = tformfwd(tf2,pts(:,1),pts(:,2));
imshow(out);
hold on
xv = xpts+1000;
yv = ypts+3000;
plot(xv(1:2),yv(1:2),'y','LineWidth',2);
plot([xv(1) xv(3)],[yv(1) yv(3)],'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;

plot(xp(1:2),yp(1:2),'y','LineWidth',2);
axis equal
grid on
hold on
cam12 = [ 0 0; -ss*3 cs*3];
plot(cam12(1,1),cam12(1,2),'ko');
plot(cam12(:,1),cam12(:,2),'k','LineWidth',2);
plot([xp(1) xp(3)],[yp(1) yp(3)],'y','LineWidth',2);
plot(xp(4:end),yp(4:end),'kx');
hold off
save loc12 cam12 xp yp
camera orientation angle -21.4851 deg
n=16;
filename = char(files(n));
rgb = imread(filename);
imshow(rgb);

%pts = ginput();
load hall_16

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
out = imtransform(rgb,tf2,'Xdata',[-1000 1000],'Ydata',[-3000 0]);
imshow(out);
[xpts ypts] = tformfwd(tf2,pts(:,1),pts(:,2));
imshow(out);
hold on
xv = xpts+1000;
yv = ypts+3000;
plot(xv(1:2),yv(1:2),'y','LineWidth',2);
plot(xv(3:4),yv(3:4),'y','LineWidth',2);
hold off
plot(xp(1:2),yp(1:2),'y','LineWidth',2);
axis equal
grid on
hold on
plot(cam12(1,1),cam12(1,2),'ko');
plot(cam12(:,1),cam12(:,2),'k','LineWidth',2);
plot([xp(1) xp(3)],[yp(1) yp(3)],'y','LineWidth',2);
plot(xp(4:end),yp(4:end),'kx');
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);
xq = cs*xs-ss*ys;
yq = ss*xs+cs*ys;

cam = [xp(4)-xq(1) yp(4)-yq(1)];
xq = xq + cam(1);
yq = yq + cam(2);

cam16 = [cam(1) cam(2); cam(1)-ss*3 cam(2)+cs*3];

hold on
plot(xq(1:2),yq(1:2),'y','LineWidth',2);
plot(cam16(1,1),cam16(1,2),'ko');
plot(cam16(:,1),cam16(:,2),'k','LineWidth',2);
plot(xq(3:4),yq(3:4),'y','LineWidth',2);
plot(xq(5:end),yq(5:end),'kx');
hold off
save loc_16 cam16 xq yq
camera orientation angle -0.660575 deg
n=19;
filename = char(files(n));
rgb = imread(filename);
imshow(rgb);

%pts = ginput();
load hall_19

hold on
plot(pts(1:2,1),pts(1:2,2),'y','LineWidth',2);
plot(pts(3:7,1),pts(3:7,2),'y','LineWidth',2);
plot(pts(4:end,1),pts(4:end,2),'wx');
hold off
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:7),yv(3:7),'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);
xq = cs*xs-ss*ys;
yq = ss*xs+cs*ys;

cam = [0 0];
xq = xq + cam(1);
yq = yq + cam(2);

cam19 = [cam(1) cam(2); cam(1)-ss*3 cam(2)+cs*3];


plot(xq(1:2),yq(1:2),'y','LineWidth',2);
axis equal
grid on
hold on
plot(cam19(1,1),cam19(1,2),'ko');
plot(cam19(:,1),cam19(:,2),'k','LineWidth',2);
plot(xq(3:7),yq(3:7),'y','LineWidth',2);
plot(xq(4:end),yq(4:end),'kx');
hold off
save loc_19 cam19 xq yq
camera orientation angle 8.54977 deg