Skip to content
Go to file
Cannot retrieve contributors at this time
139 lines (87 sloc) 5.14 KB


Take a picture of a "Grade-it" math worksheet and AutoMark will automatically grade it!

This project is intended as a proof-of-concept (that automatically grading math worksheets is feasable) prior to creating a website that generates worksheets and an app that grades them.

Final result

AutoMark reads a "Grade-it" QR code/form code and uses that to get the associated answer key. It then reads students' handwritten responses. It displays a color coded worksheet showing which problems the student got right and wrong.

Adapted from SnapSuduku by Prajwal


  • Python 3

    • Download from here
  • PyZBar

    • sudo apt-get install libzbar0
  • All other requirements can be installed using:

    • pip install -r requirements.txt

Running AutoMark:

git clone
cd AutoMark/AutoMark
python <path-to-input-image>

An Example Input:

Here's a image of a "Grade-it" worksheet from a smartphone:

Input Worksheet Image

The current code gives this output:

Final result

The student filled in 9 problems correctly and 5 problems incorrectly.

The program correctly marked 12 problems (8 correct in green and 4 incorrect in red).

The program marked 2 problems as unknown (with a yellow box and black text). It was unable to segment the connected digits on problem #2 and unable to read the student's handwriting on problem #10.


  1. Basic image preprocessing - Thresholding.
  2. Crop out the worksheet.
  3. Warp the perspective of the worksheet (to make it rectangular).
  4. Read the form code from the QR Code (using PyZBar)
  5. Get the boxes where the student entered their handwritten answers (filtering contours).
  6. Segment the handwritten digit string (this needs to be improved, currently contours are used which don't work when digits touch)
  7. Transform the segmented digits to MNIST's standards
  8. Look up the answer key from the form code.
  9. Predict the value of the handwritten digits using a pretrained model from Keras's example Convolutional Neural Network for MNIST.
  10. Display the graded result on the worksheet.

A Detailed Step-by-Step Example:

Two images are shown at some steps. The various steps perform best with different preprocessing so rather than keeping one preprocessed image, the original image is also cropped and kept.

After Preprocessing:


Crop out the largest contour:

Cropped worksheet thresh

Warp perspective to a letter sized rectangle:


Crop out the cells:

Cell 1 Cell 3

Remove the borders:

Without borders 1 Without borders 2

Apply thresholding and use contours to segment digit strings

Thresh digits Thresh digits 2

Note this process will not work when digits touch (like the 2 and 3 below):

Touching digits

Segmented the digits:

Segmented 1
Segmented 2

Format the digits to match MNIST specs:


Final Result:

Final result


  • Test AutoMark with a larger variety of images from different cameras.
  • Improve digit string segmentation (watershed?).
  • Implement a form code database.

Related Projects:

Grade-it: A math worksheet generator


Thank you to the creators and contributors of SnapSuduku

Thank you to octagonaltree for the mentorship and guidance.

Thank you to Chris Lowen for the feedback.

You can’t perform that action at this time.