Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

your code doesn't contain getPerspectiveTransform. do you have the homography matrix returned by that call?

the homography matrix lets you translate any point in one image to the corresponding point in the other... but if you invert it, you can do the opposite!

you may or may not need np.linalg.inv to invert the matrix, and you need to matrix-multiply (np.dot or @-operator between operands) your point in a specific format with the matrix.

when you have a point (x,y), you need to construct a vector v = np.matrix([x, y, 1]).T, and then you can say v_mapped = M @ v; v_mapped /= v_mapped[2]. now you have the point (x', y') in v_mapped[0:2]

I believe OpenCV's perspectiveTransform() procedure does this for you: https://docs.opencv.org/master/d2/de8/group__core__array.html#gad327659ac03e5fd6894b90025e6900a7

in the numpy case you may have to reshape the src argument suitably. if you have your points as an array of row vectors [[x,y], [x,y], ...], then you may have to reshape it to be (-1, 1, 2) and pass that