Using findHomography to align scanned documents; How do I avoid obviously-bad (non-planar/3D) transforms?

asked 2019-08-27 12:38:23 -0500

cccoleman gravatar image

We have hundreds of scanned copies of a form; We need to align each image to a template, correcting for translation and rotation in 2-Dimensions.

After trying some FFT-based methods, we've gotten our best results using OpenCV to do the alignment as described in the article Image Alignment (Feature Based) using OpenCV.

When it works, it works perfectly. But often it produces very strange results.

Sometimes the results are moderately skewed into the 3rd Dimension, but usually the bad alignments are ridiculous to the point of resembling abstract art.

Is there a way to constrain findHomography to only planar results? If not, is there a way to detect non-planar results in findHomography's output?

Screenshots below, the blue regions are my redactions.

edit retag flag offensive close merge delete


Can you add the original images?

How the scanned documents look like? If the document is fully visible, I would instead try to detect the 4 corners (e.g. using the contours, using lines detection and lines intersection ) and estimate the homography on these corners.

Eduardo gravatar imageEduardo ( 2019-08-27 13:28:52 -0500 )edit

Unfortunately, the corners are usually completely invisible -- but not always.

cccoleman gravatar imagecccoleman ( 2019-08-27 13:49:25 -0500 )edit

I would try something like line detection to get the orientation of the sheet since you should get only in-plane rotation if you are using a scanner.

Eduardo gravatar imageEduardo ( 2019-08-28 03:56:48 -0500 )edit