6

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?

Community
  • 1
  • 1
TomSwift
  • 38,979
  • 11
  • 115
  • 147
  • Duplicate of this question: http://stackoverflow.com/questions/1194352/proportions-of-a-perspective-deformed-rectangle – TomSwift Jul 12 '12 at 01:05

1 Answers1

4

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.

Mar de Romos
  • 699
  • 2
  • 9
  • 19
  • Thanks; good info. But not what I needed; my primary need was to find the ratio of W to H for the output rectangle, and I found the answer in the similar question I found and marked. – TomSwift Jul 17 '12 at 15:59