2

I have to process a lot of scanned IDs and I need to extract photos from them for further processing. Here's a fictional example:

enter image description here

The problem is that the scans are not perfectly aligned (rotated up to 10 degrees). So I need to find their position, rotate them and cut out the photo. This turned out to be a lot harder than I originally thought.

  • I checked OpenCV and the only thing I found was rectangle detection but it didn't give me good results: the rectangle not always matches good enough on samples. Also its image matching algorithm works only for not-rotated image since it's just a brute force comparison.

  • So I though about using ARToolkit (augmented reality lib) because I know that it's able to very precisely locate given marker on an image. But it it seems that the markers have to be very simple, so I can't use a constant part of the document for this purpose (please correct me if I'm wrong). Also, I found it super-hard to compile it on Ubuntu 11.10.

  • OCR - haven't tried this one yet and before I start my research I'd be thankful for any suggestions what to look for.

I look for a C(preferable)/C++ solution. Python is an option too.

Bart
  • 19,692
  • 7
  • 68
  • 77
user1038722
  • 51
  • 1
  • 3

1 Answers1

1

If you don't find another ideal solution, one method I ended up using for OCR preprocessing in the past was to convert the source images to PPM and use unpaper in Ubuntu. You can attempt to deskew the image based on whichever sides you specify as having clearly-defined edges, and there is an option to bypass the filters that would normally be applied to black and white text. You probably don't want those for images.

Example for images skewed no more than 15 degrees, using the bottom and right edges to detect rotation:

unpaper -n -dn bottom,right -dr 15 input.ppm output.ppm

unpaper was written in C, if the source is any help to you.

robots.jpg
  • 5,001
  • 1
  • 38
  • 41