Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“„ OMR Sheet Evaluation using OpenCV

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.


๐Ÿš€ Features

  • 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


๐Ÿ“Œ Technologies Used

  • Python
  • OpenCV
  • NumPy
  • Computer Vision techniques (Contours, Morphology, Thresholding)

๐Ÿง  How It Works (Pipeline)

  1. Preprocessing

    • Converts image to grayscale

    • Applies Gaussian blur

    • Uses:

      • Adaptive Thresholding for reference image
      • OTSU Thresholding for filled image
  2. OMR ROI (Region Of Interest) Detection

    • Finds the largest rectangular contour (main OMR container)
    • Crops the region of interest for accurate processing
  3. Bubble Detection

    • Uses morphological operations

    • Filters contours based on:

      • Area
      • Aspect ratio
      • Circularity
      • Extent
  4. Bubble Sorting

    • Sorts bubbles left-to-right (columns)
    • Then top-to-bottom (questions)
  5. Answer Detection

    • Counts filled pixels inside each bubble
    • A bubble is considered marked if > 40% of its area is filled
  6. 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

๐Ÿงฎ Scoring Logic

Case Score
Correct +2
Incorrect โˆ’1
Skipped 0

๐Ÿงฉ Configuration

Currently configured for 20 questions:

block_of_questions = 4
questions_per_block = 5
options_per_question = 4

Answer Key Format

key = {
  1: "A", 2: "B", 3: "C", 4: "D",
  ...
}

You can easily modify this for different exams.


๐Ÿ“‚ Project Structure

.
โ”œโ”€โ”€ images/
โ”‚   โ”œโ”€โ”€ OMR_ref2.png     # Reference (blank) OMR sheet
โ”‚   โ””โ”€โ”€ OMR_filled2.png  # Filled OMR sheet
โ”œโ”€โ”€ main.py              # Main Python script
โ””โ”€โ”€ README.md

๐Ÿ› ๏ธ Requirements

  • Python 3.7+
  • OpenCV
  • NumPy

Install dependencies:

pip install opencv-python numpy

โ–ถ๏ธ How to Run

python main.py

The program will:

  • Display the graded OMR ROI with markings
  • Print the final score in the console

๐Ÿ”„ Processing Flow

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]
Loading

๐Ÿ“Š Output & Visual Results

This section demonstrates the end-to-end OMR evaluation pipeline, from the reference template to the final graded output.


๐Ÿงพ Reference OMR Template

Used to detect the bubble layout and define the evaluation structure.

OMR Reference


โœ๏ธ Filled OMR Sheet

Student-marked OMR sheet provided as input for evaluation.

OMR Filled


๐Ÿ”ข Bubble Indexing Visualization

Illustrates how bubbles are detected, indexed, and mapped to questions and options internally.

OMR Bubble Indexing


โœ… Final Graded Output

Color-coded evaluation with score overlay:

  • ๐ŸŸข Green โ†’ Correct answers
  • ๐Ÿ”ด Red โ†’ Incorrect selections
  • ๐ŸŸ  Orange โ†’ Skipped questions

OMR Output


๐Ÿ–ฅ๏ธ Console Output

Bubbles successfully filtered: 80
Detected 80 bubbles. Expected 80
Final Score: 32

๐Ÿงฉ Generate Your Own OMR Sheet (20 Questions)

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/

๐Ÿ“Œ Recommended Settings

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

๐Ÿ–จ๏ธ Usage Tip

  • 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


โš ๏ธ Notes & Limitations

  • 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

๐Ÿ”ฎ Possible Enhancements

  • ๐Ÿ“„ Support multiple OMR templates
  • ๐Ÿ“ฆ Automatic question count detection
  • ๐Ÿ“Š CSV / Excel export
  • ๐Ÿ–ฅ๏ธ GUI interface
  • ๐Ÿค– ML-based bubble classification

About

OMR Sheet Evaluation system using Python and OpenCV. Automatically detects answer bubbles, evaluates marked responses, calculates scores, and visualizes grading results. Built with Computer Vision techniques including contour detection, thresholding, morphology, and pixel-density analysis for automated exam assessment.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages