反向同位素

时间:2017-02-22 16:18:44

标签: c++ opencv projection perspective homography

我使用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)

现在我只想回到原始图像的“点”集,这样我现在就可以看到原始图像中的一组兴趣点。

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

2 个答案:

答案 0 :(得分:1)

要查找反单应性,只需切换points_dstpoints_src

H_inv= findHomography(points_dst, points_src);

然后,如果将H_inv应用于由H变换的点,则将获得原始点。

答案 1 :(得分:1)

您确实可以再次使用findHomography(),但是由于有了composition properties of such matrix,逆向转换的一种更为优雅,准确和快速的方法是简单地求反单应矩阵 strong>。

这是使用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.]]]