Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
139 lines (87 sloc) 5.14 KB

AutoMark

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

Prerequisites:

  • 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 https://github.com/tutordelphia/AutoMark.git
cd AutoMark/AutoMark
python automark.py <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.

Algorithm

  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:

Preprocessing

Crop out the largest contour:

Cropped worksheet thresh

Warp perspective to a letter sized rectangle:

Warped

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:

MNIST 1 MNIST 2

Final Result:

Final result


TODO:

  • 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


Acknowledgements

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.