Calculating Destinations for OpenCV findHomography

EDIT . I found this similar question with a very detailed answer:

proportions of a perspective-deformed rectangle


I use the OpenCV methods findHomography() and warpPerspective() to “skew” a photograph of a sheet of paper. It basically works for me, but I'm stuck in the details.

The part that I don’t understand how to do this is to calculate the optimal set of destination points for input in findHomography() . I know that I want my output to be rectangular, but I do not know the ratio of width to height of the rectangle. I also want the size of the output rectangle to be such that it minimizes scaling of the output image when applying the transform through warpPerspective() . All I have is four points that form the quadrangle that I want to convert in the original image. How to calculate the optimal size destination rectangle?

+6
source share
1 answer

The findHomography() method will need four points (if using Direct Linear Transformation ). If you need an optimal set, you will need a 4-point set in which DLO homography gives a minimal transcoding error. I mean, you need a method that detects sheets / outliers for a particular mathematical model with DLT .

This method is RANSAC , and OpenCV implemented it. You will find findHomography() examples in combination with RANSAC .

I personally find one problem with this, and this is the number of RANSAC iterations in OpenCV that is too large. If you are looking for the best speed, you have to dig into the codes.

+4
source

Source: https://habr.com/ru/post/920271/


All Articles