script6 (directed homography)
clear
close all
rgb = imread('image_6.jpg');
imshow(rgb);
do_input = false;
if do_input
imshow(rgb);
pt = ginput(1);
save script5 pt
else
load script5
end
hold on
plot(pt(1),pt(2),'bx','MarkerSize',11,'LineWidth',2);
hold off
load calib2
R = cameraParams.RotationMatrices(:,:,4);
V = cameraParams.TranslationVectors(4,:)
f = 879.2;
V =
-18.5735 -26.3871 81.0641
KK = [ f 0 320; 0 f 320; 0 0 1];
T1 = R/KK;
newcp = h2e(T1*e2h(pt'));
M = [600 0 0; 0 600 0; 0 0 1]*[eye(2,2) -newcp ; 0 0 1];
T = M*T1;
tf = projective2d(T');
NW = 300;
imageSize = [600 600];
xWorldLimits = [-NW NW];
yWorldLimits = [-NW NW];
RA = imref2d(imageSize,xWorldLimits,yWorldLimits);
[out, RB] = imwarp(rgb,tf,'OutputView',RA);
imshow(out);
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
d = R*V'/12
scl = 600/d(3)/12;
fprintf('scale %g pixels/inch\n',scl);
d =
5.1914
0.8719
5.0154
scale 9.96923 pixels/inch