Skip to content
Advertisement

How to make kornia HomographyWarper behave like OpenCV warpPerspective?

As the title says, I want to use HomographyWarper from kornia so that it gives the same output as OpenCV warpPerspective.

JavaScript

With the code above, I get the following output:

enter image description here enter image description here enter image description here

With normalized_coordinates=False, I get the following output:

enter image description here

Apparently the homography transformation is applied differently. I would love to know the difference.

Advertisement

Answer

You need to make two changes:

  1. Use the same padding mode.

In your example cv2 uses cv2.BORDER_REFLECT101 but the kornia zeros So change zeros to padding_mode='reflection' when calling kornia.

  1. You need to specify normalized_homography=False.

So the modified version:

JavaScript

Or simply:

JavaScript

The result (cv2/kornia):

enter image description here

HomographyWarper internally calls homography_warp function https://github.com/kornia/kornia/blob/f696d2fb7313474bbaf5e73d8b5a56077248b508/kornia/geometry/transform/homography_warper.py#L96 but HomographyWarper does not provide normalized_homography argument and homography_warp does.

Complete example:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement