This project implements an Optical Mark Recognition (OMR) system using Python and OpenCV. It evaluates a filled OMR sheet by comparing it against a reference (blank) OMR template and automatically calculates the final score with visual feedback.
-
Detects the main OMR region automatically
-
Identifies and filters answer bubbles accurately
-
Sorts bubbles column-wise and question-wise
-
Detects marked answers using pixel density analysis
-
Grades answers using a configurable answer key
-
Visualizes:
- โ Correct answers (Green)
- โ Incorrect answers (Red)
โ ๏ธ Skipped questions (Orange)
-
Displays final score directly on the evaluated image
- Python
- OpenCV
- NumPy
- Computer Vision techniques (Contours, Morphology, Thresholding)
-
Preprocessing
-
Converts image to grayscale
-
Applies Gaussian blur
-
Uses:
- Adaptive Thresholding for reference image
- OTSU Thresholding for filled image
-
-
OMR ROI (Region Of Interest) Detection
- Finds the largest rectangular contour (main OMR container)
- Crops the region of interest for accurate processing
-
Bubble Detection
-
Uses morphological operations
-
Filters contours based on:
- Area
- Aspect ratio
- Circularity
- Extent
-
-
Bubble Sorting
- Sorts bubbles left-to-right (columns)
- Then top-to-bottom (questions)
-
Answer Detection
- Counts filled pixels inside each bubble
- A bubble is considered marked if > 40% of its area is filled
-
Grading & Visualization
- +2 marks for correct answers
- โ1 mark for incorrect answers
- 0 for skipped questions
- Draws color-coded circles on the evaluated OMR image
| Case | Score |
|---|---|
| Correct | +2 |
| Incorrect | โ1 |
| Skipped | 0 |
Currently configured for 20 questions:
block_of_questions = 4
questions_per_block = 5
options_per_question = 4key = {
1: "A", 2: "B", 3: "C", 4: "D",
...
}You can easily modify this for different exams.
.
โโโ images/
โ โโโ OMR_ref2.png # Reference (blank) OMR sheet
โ โโโ OMR_filled2.png # Filled OMR sheet
โโโ main.py # Main Python script
โโโ README.md
- Python 3.7+
- OpenCV
- NumPy
Install dependencies:
pip install opencv-python numpypython main.pyThe program will:
- Display the graded OMR ROI with markings
- Print the final score in the console
flowchart TD
A[Reference OMR] --> B[Preprocessing]
C[Filled OMR] --> B
B --> D[Detect OMR ROI]
D --> E[Bubble Detection]
E --> F[Bubble Sorting]
F --> G[Answer Detection]
G --> H[Grading & Visualization]
H --> I[Final Score]
This section demonstrates the end-to-end OMR evaluation pipeline, from the reference template to the final graded output.
Used to detect the bubble layout and define the evaluation structure.
Student-marked OMR sheet provided as input for evaluation.
Illustrates how bubbles are detected, indexed, and mapped to questions and options internally.
Color-coded evaluation with score overlay:
- ๐ข Green โ Correct answers
- ๐ด Red โ Incorrect selections
- ๐ Orange โ Skipped questions
Bubbles successfully filtered: 80
Detected 80 bubbles. Expected 80
Final Score: 32
To test or customize this project, you can generate your own 20-question OMR sheets using the online OMR generator below:
๐ OMR Sheet Generator ๐ https://omrsheetgenerator.com/
When generating the OMR sheet, use the following configuration for compatibility with this project:
- Number of Questions: 20
- Options per Question: 4 (A, B, C, D)
- Layout: 4 columns ร 5 questions per column
- Bubble Shape: Circle
- Print Scale: 100% (no scaling)
โ ๏ธ Important: Any change in layout (number of questions, columns, or options) requires updating the configuration values in the code:
block_of_questions
questions_per_block
options_per_question-
Use the generated sheet as:
- Reference Image โ unfilled OMR
- Filled Image โ marked OMR
-
Ensure:
- Good lighting
- Minimal skew
- Clear bubble filling (pen/pencil)
-
Use virtual environment
- Assumes consistent OMR layout
- Bubble count must exactly match configuration
- Lighting conditions should be reasonably uniform
- Currently supports only one OMR format at a time
- ๐ Support multiple OMR templates
- ๐ฆ Automatic question count detection
- ๐ CSV / Excel export
- ๐ฅ๏ธ GUI interface
- ๐ค ML-based bubble classification



