I'm trying to apply projective homography on an image and a marked rectangle. My solution works well for all of the affine transformations, but in the case of projective transformations, there's a systematic error that keeps increasing when I run it in a loop. I can't seem to figure out the reason. A quick answer will be really appreciated. please have look on the code and screen shots. Thanks
clc;clear;close all;
background_img_dir = 'D:/eyedeus/dataset/background_imgs/';
background_img = [background_img_dir '1.jpg'];
img = imread('D:/workspace/dataset/taj.jpg');
rect = [236 333 325 226; 304 303 441 440];
K = eye(3);
steps=pi/100; ang=-steps;
rotaxis=[0.5,0.5,1]; rotaxis=rotaxis./norm(rotaxis);
N = 100;
for i = 1:N
ang=ang+steps;
R=makehgtform('axisrotate',rotaxis,ang);
H = K * R(1:3,1:3) * inv(K);
Hp = H';
T = maketform('projective', Hp);
xsize=size(img,1);
ysize=size(img,2);
t_img = imtransform(img, T, 'UData',[0 1],'VData',[0 1]);
x = [rect ; ones(1,4)];
pts = H * x;
pts = pts(1:2, :) ./ repmat(x(3,:),2,1);
clf;
imshow(t_img); hold on;
line([pts(1,:) pts(1,1)], [pts(2,:) pts(2,1)], 'color', 'b', 'LineWidth', 2);
pause(0.1);
end
First image with marked blue rectangle:
After applying homography: