简体   繁体   English

在matlab中使用imtransform在图像和标记的矩形上应用单应性

[英]applying homography on an image and a marked rectangle using imtransform in matlab

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: 应用单应性之后:

Looks like a typo in the division step of the homography. 在单应性的除法步骤中看起来像是一个错字。 Instead of this: 代替这个:

pts = H * x;
pts = pts(1:2, :) ./ repmat(x(3,:),2,1);

you want this: 你要这个:

pts = H * x;
pts = pts(1:2, :) ./ repmat(pts(3,:),2,1);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM