I get an H matrix using findHomography function.
H = findHomography(points_src, points_dst);
Then, I use H with warpPerspective to get a perspective projection of the image
warpPerspective(im_src, im_dst, H, Size(100, 100));
and from here I get a set of points of interest
vector<Point2f> points = some_function(im_dst)
Now I want to get back only the set of "points" to the original image and in this way I will now the set of points of interest in the original image.
For this task, I guess that I need to use again warpPerspective with the flag WARP_INVERSE_MAP but this does not work.
You could indeed use findHomography()
once again, but thanks to the composition properties of such matrix, a much more elegant, accurate and fast way to reverse the transformation is to simply inverse the homography matrix.
Here is a little demonstration using 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.]]]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With