Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

calculating the destination points for OpenCV's findHomography

EDIT: I've now found this similar question with a very detailed answer:

proportions of a perspective-deformed rectangle


I'm using OpenCV's findHomography() and warpPerspective() methods to "de skew" a photograph of a sheet of paper. I have this largely working but I'm stuck on a detail.

The part I don't understand how to do is to calculate the optimum set of destination points to input to findHomography(). I know that I want my output to be rectangular, but I dont know the ratio of the width to height of the rectangle. I also want the output rectangle to be sized such that there is minimal scaling of the output image when I apply the transform via warpPerspective(). All I have are the four points that form the quadrilateral I want to transform in the source image. How do I calculate an optimum-sized destination rectangle?

like image 296
TomSwift Avatar asked Jul 11 '12 21:07

TomSwift


1 Answers

The findHomography() method will need four points (if using Direct Linear Transform). If you want the optimal set you will need the 4-point set which DLT's homography gives the minimum reprojection error. I mean, you need a method that detects inliers/outliers for the particular mathematical model od the DLT.

THis method is RANSAC, and OpenCV has it implemented. You will find examples of findhomography() combined with RANSAC.

I personally find one problem with this and it is the number of iterations of RANSAC in OpenCV, which is too high. If you are looking for optimal speed you will have to dig into the codes.

like image 176
Mar de Romos Avatar answered Oct 06 '22 04:10

Mar de Romos