6

I have PDF files or JPG images that I need to print (these are formulars that will be filled in by hand), and I need that:

  • after scan, the image should be rotated / scaled perfectly with Python, so that I can access to certain parts of the formular with x, y coordinates

  • the scanned images should be recognized with a number ID.

What kind of pattern should I add on the formular paper, so that a Python library (which one?) will be able to crop it / rotate it / identify it with an ID?

I was thinking about adding a QR-code (containin a number ID) on top left of paper, and a QR-code on bottom right of the paper, or maybe also "hirondelles" symbols:

The QR code would be generated with qrcode library:

import qrcode
img = qrcode.make('ID1138934')

and added on top the PDF with this method.


Note:

enter image description here

Basj
  • 41,386
  • 99
  • 383
  • 673

1 Answers1

1

This task needs the combination of two techniques:

  • First step: detect the x,y coordinates of the 4 corners of each QR code. The Python library zbar is useful for this. The code in this question + the answer shows how to do it.

  • Second step: now a deskewing / perspective correction / "homography" is needed. Here is how to do it with Python + OpenCV.

Basj
  • 41,386
  • 99
  • 383
  • 673
  • One thing I would like to point is that you will need 4 corners with sub-pixel accuracy i.e. in decimal floating points. `zbar` gives integral coordinates which is not sufficient to get a very good result for perspective correction. I found that the new `OpenCV 4.1` has similar functionality as `zbar` and it gives 4 corners in floating point. But its not as robust as `zbar`. – abggcv May 23 '19 at 16:28