dh1a (directed homography about z-axis of camera)

clear
close all
% test1  filename='mod_3.jpg';
filename = 'script5c.jpg';
rgb = imread(filename);
imshow(rgb);
vid = VideoWriter('test3.mp4','MPEG-4');

open(vid);

for thetad = linspace(0,90,120);
theta = thetad*pi/180;
vi = [cos(theta) sin(theta) 0];
vk = [0 0 1];
vj = cross(vk,vi);
R = [vi; vj; vk];
f = 879.2;

pt = [320 320];
%pt = [320 320+ 300*sin(theta)];


KK = [ f 0 320; 0 f 320; 0 0 1];
T1 = R/KK;

newcp = h2e(T1*e2h(pt'));

M = [300 0 0; 0 300 0; 0 0 1]*[eye(2,2) -newcp ;  0 0 1];
T = M*T1;

tf = projective2d(T');
NW = 400;
imageSize = [800 800];
xWorldLimits = [-NW NW];
yWorldLimits = [-NW NW];

RA = imref2d(imageSize,xWorldLimits,yWorldLimits);

[out, RB] = imwarp(rgb,tf,'OutputView',RA);
imshow(out);
frame = getframe
writeVideo(vid,frame);
end

close(vid);
% do_input = false;
% if do_input
%     imshow(out);
%     hd1 = imdistline;
%     hd2 = imdistline;
%     pause
%     pos1 = hd1.getPosition();
%     pos2 = hd2.getPosition();
%     save dh2 pos1 pos2
% else
%     load dh2
%     hd1 = imdistline(gca,pos1(:,1),pos1(:,2));
%     hd2 = imdistline(gca,pos2(:,1),pos2(:,2));
% end