【问题标题】:applying homography on an image and a marked rectangle using imtransform in matlab在matlab中使用imtransform在图像和标记的矩形上应用单应性
【发布时间】:2014-11-21 18:57:09
【问题描述】:

我正在尝试在图像和标记的矩形上应用投影单应性。我的解决方案适用于所有仿射变换,但在投影变换的情况下,当我在循环中运行它时,系统误差会不断增加。我似乎无法弄清楚原因。快速回答将不胜感激。请查看代码和屏幕截图。谢谢

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

第一张带有蓝色矩形标记的图片:

应用单应性后:

【问题讨论】:

  • 阿里,你知道如何在 x 轴上应用单应性吗?请查看我的question

标签: matlab transformation homography projective-geometry


【解决方案1】:

看起来像是单应性除法步骤中的错字。而不是这个:

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

你想要这个:

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

【讨论】:

  • 没用,我知道 imtransform 中单应矩阵的符号不同,我想不通,这就是归一化不起作用的原因,结果稍有偏差归一化,归一化很奇怪。
  • 好的,然后还有一个想法:您指定 UData 和 VData,以便在转换之前在 0 和 1 之间重新调整图像坐标。您可能需要在转换之前按图像宽度和高度重新缩放矩形坐标,然后在转换后再次回到像素。
  • @Peter 你能检查一下这个question
猜你喜欢
  • 2018-04-27
  • 2015-07-11
  • 1970-01-01
  • 1970-01-01
  • 2014-01-16
  • 1970-01-01
  • 1970-01-01
  • 2013-04-27
  • 1970-01-01
相关资源
最近更新 更多