DEV Community

207studio
207studio

Posted on

Cropping scanned answer sheets with a QR code as the anchor (Python + OpenCV)

I'm an elementary school teacher in Korea and I build small tools for my own grading. The slowest part was never the grading itself. It was sorting a scanner batch where pages come out shuffled, rotated, and front and back mixed up.

The fix that worked: print a small QR in the corner of every sheet. It carries the exam ID, the student number and the side. Then for each scanned page:

  1. Find the QR at any rotation and read who and which side it is.
  2. Use the QR position plus the table border to rotate and deskew the page.
  3. Cut every answer cell into its own image, so a person or an OMR reader looks at one cell at a time.

In my test batch, 6 shuffled and rotated scans came out as 3 students with 13 clean cells each, fronts and backs paired automatically. It works offline at 150 dpi.

Happy to answer questions about the alignment step, which took the most trial and error.

I made this into a small Python package with full source and a 3-command demo: https://207studio.dev/products/qr-cropper/ One-time purchase.

Top comments (0)