Assignment 1: Name and Roll-Number Detection from Exam Sheets
EC331 Computer Vision
Department of Computer Science
University of the Punjab
Author: Nazar Khan
|
|
Sample Input |
Sample Output |
Write a program to detect student names and roll-numbers from exam cover sheets. A sample image is shown above. You are given a dataset of 101 images.
Your program should draw green rectangles around each detected name and roll-number, and save the resulting image in the results/ folder.
Your program should also save the pixel coordinates of the top-left and bottom-right of each rectangle along with the image name in a CSV file called boxes.csv. For example, for the 101 images, the boxes.csv file should contain 101 lines as follows.
image1.jpg 266 268 317 483 244 684 293 864
image2.jpg 249 283 302 506 235 693 282 858
⋮
image101.jpg 270 255 331 460 267 659 303 881
Each line contains 9 items in the following order:
- Name of the image file
- Row coordinate of top-left corner of box detected around the student's roll-number.
- Column coordinate of top-left corner of box detected around the student's roll-number.
- Row coordinate of bottom-right corner of box detected around the student's roll-number.
- Column coordinate of bottom-right corner of box detected around the student's roll-number.
- Row coordinate of top-left corner of box detected around the student's name.
- Column coordinate of top-left corner of box detected around the student's name.
- Row coordinate of bottom-right corner of box detected around the student's name.
- Column coordinate of bottom-right corner of box detected around the student's name.
If any box is not detected, then its coordinates should be replaced by 0 0 0 0. For example, if for image2.jpg, only the student's name was detected, then you will save this result as
image2.jpg 0 0 0 0 235 693 282 858
Similarly, for other cases with missing boxes.
Directory Structure:
The assignment will be graded automatically. The grading script assumes the following directory and file structure.
- top_halves/ <-- Contains the 101 images
- A1_solution/ <-- The folder containing your solution
- results/ <-- Will contain your results on 101 images showing the detected boxes in green
- A1_solution.py <-- Your solution. Running 'python A1_solution.py' should populate the 'results/' folder and generate 'boxes.csv'
- template.jpg <-- The image region used as a template IN CASE your solution uses template matching.
- boxes.csv <-- The coordinates of all detected boxes.
Submission:
- You will submit a zip file named YourRollNumber_Assignment1.zip.
- If your solution contains only 1 Python file, that file MUST be named A1_solution.py.
- If your solution contains more than 1 Python files, then the main file MUST be named A1_solution.py.
- If your solution depends on a template image,
- save it as template.jpg,
- the automatic grading script will NOT mark the template region itself,
- your code MUST read the template.jpg file if it exists,
- The automatic grading script will run the command python A1_solution.py and reproduce all your results. So, before submission, make sure that this command works correctly with the directory structure mentioned above.
- You should submit .py files and the template.jpg file if you use any.
- Do NOT submit any results or .csv files.
Hints:
- For one of the images, you may choose a reference area as a template. Then use this template to find the same area in all the images. For example, your template can be the image region representing the text “University of the Punjab” or some other region that you think will appear on all exam sheets. The student's roll-number and name can be found relative to the detection of this template. OpenCV has built-in functions for marking an image region (
cv2.selectROI
) to use as a template and also for template matching (cv2.matchTemplate
).