【问题标题】:Inverse Homography逆单应性
【发布时间】:2017-02-22 16:18:44
【问题描述】:

我使用 findHomography 函数得到一个 H 矩阵。

H = findHomography(points_src, points_dst);

然后,我使用 H 和 warpPerspective 来获得图像的透视投影

warpPerspective(im_src, im_dst, H, Size(100, 100));

从这里我得到一组兴趣点

vector<Point2f> points = some_function(im_dst)

现在我想只取回原始图像中的“点”集,这样我现在将获得原始图像中的兴趣点集。

对于这个任务,我想我需要再次使用带有 WARP_INVERSE_MAP 标志的 warpPerspective 但这不起作用。

【问题讨论】:

    标签: c++ opencv projection perspective homography


    【解决方案1】:

    您确实可以再次使用findHomography(),但感谢composition properties of such matrix,一种更优雅、准确和快速的逆转换方法是简单地单应矩阵求逆

    这是一个使用 Python 的小演示:

    import cv2
    import numpy as np
    
    source = np.float32([[0, 0], [100, 0], [100, 100], [0, 100]])
    dest = np.float32([[0, 0], [-1000, 0], [-1000, -1000], [0, -1000]])
    
    points = np.float32([[[50, 50]]])
    
    homography, _ = cv2.findHomography(source, dest)
    
    transformed = cv2.perspectiveTransform(points, homography)
    
    print(transformed)
    # => [[[-500. -500.]]]
    
    homography_inverse = np.linalg.inv(homography)
    
    detransformed = cv2.perspectiveTransform(transformed, homography_inverse)
    
    print(detransformed)
    # => [[[50. 50.]]]
    

    【讨论】:

    • cv 也有矩阵求逆的内置函数:cv::Mat::inv.
    【解决方案2】:

    要找到逆单应性,只需切换points_dstpoints_src

    H_inv= findHomography(points_dst, points_src);
    

    那么如果你将H_inv应用到H转换的点上,你将得到原始点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-10
      • 1970-01-01
      相关资源
      最近更新 更多