Click here to Skip to main content
Click here to Skip to main content

C# - Optical Marks Recognition (OMR) Engine 1.0

By , 20 Aug 2013
Rate this:
Please Sign up or sign in to vote.

Introduction 

OMR (wiki) are answer sheets that are not intended to be read by a human being. This projects eliminates the need to buy OMR reading machines and even a photo scanner for computer. Any 2MP< mobile phone camera with autofocus will do the job.

Background  

I Googled to to find a good OMR engine but in vain, so I decided to make my own. Normally in schools and colleges they use specialized machines to read OMR answer sheets. In my case I needed to eliminate the need of buying the OMR reader machine, even the scanner! Pictures taken with a 2MP mobile phone camera (autofocus required) can be read through this engine. At an initial level, I have created my own sheet types that can be read. The image processing part utilizes AForge.Net's image processor (libraries included in the download).  

[EDITED/ADDED]  Will it work with other OMR sheets?

It looks like a lot of people have asked a same question repeatedly in the feedback.  

"Can we use any other OMR sheet with this engine?" .

And the answer is, "NO".

Why? Because of the Paper image extraction Algorithm used in method ExtractPaperFromFlattened(). It identifies a paper out of a scanned immage by finding the 4 crossed circular symbols located on the paper. THESE SYMBOLS DEFINE THE BOUNDARIES OF PAPER AND THUS, THE INFORMATION ABOUT CROPPING, RESCALING AND SKEWING OF PAPER IS ESTIMATED.

So, no symbols, NO DETECTION of paper.

Using the Code

After adding all the references (AForge and OMR) you can use the simplest method overload to extract an OMR wrapped sheet from camera/scanner image. 

Raw images must contain one clear view of the supported sheet formats (Printable PDF is in the download). e.g.

Bitmap unf = new Bitmap(panel1.BackgroundImage);
OpticalReader reader = new OpticalReader();
panel1.BackgroundImage = (System.Drawing.Image)reader.ExtractOMRSheet(unf, 
    "sheets.xml" , OMREnums.OMRSheet.A550);

This will extract sheet as this:

And once the sheet is extracted you can process it using methods like:

OpticalReader rr = new OpticalReader();
MessageBox.Show(rr.getRegNumOfSheet(panel1.BackgroundImage, 
    OMREnums.OMRSheet.A550, "sheets.xml",false).ToString());

http://img33.imageshack.us/img33/3936/omr3a.jpg 

Sheet Detection From Camera/Scanner Image 

The procedure to detect a sheet involves detection of a sheet's corners. In the printed document corners are marked with specific binary images. We detect them, we detect a sheet.

  1. So, first of all, we need to flatten out the picture using correct contrast, fill, threshold and invert filter. As a start point, raw images with no contrast, brightness or fill correction are inverted. Given a threshold, the image is then converted to binary. This image is called a "Flattened Image" and is obtained by using the "OMR.OpticalReader.flatten" method.
  2. Once an image is flattened out, blob detection starts. In the first stage all sizes and kinds of blobs starting from a minimum blob size are detected (this ensures we remove noise grains blobs)
  3. The left edge is detected first and then we detect the right one edge of sheet.
  4. Out of hundreds of blobs detected out of a picture in first filter, the wrong sized blobs are filtered out by checking their size to camera/scanner image's size ratio.
  5. In the second filter, blobs placed on the wrong side of the image are filtered out
  6. In the third filter, blobs having insanely wrong aspect ratios are filtered out (ensuring we detect and reject the blobs produced by bends/lines on sheet)
  7. As a last filter to blobs, all the blobs are compared against a mirrored corner image (mirrored because we inverted the image in first step).
  8. Filtered out blobs are once again, re-verified that they are exactly four in quantity and are placed on the right sides of sheet. Also, left and right edges don't vary too much in their lengths.
  9. Verified blobs represent the real location of sheet corners in image coordinate system.
  10. Images can be cropped through of these points from the unflattened image and wrapped to produce a perfect rectangular image called OMR Sheet.
  11. If all the above filters yield only 4 corner blobs, the process is continued, otherwise a recursive call is made on the same function with the same parameters, but with altered contrast correction that may yield in a better results value.

See the code with line-line comments on the "OMR.OpticalReader.ExtractOMRSheet" method.

Reading the Extracted Sheet

Major image processing lied in the image extraction part. Now the next stage is to read the OMR sheet.

Normally OMR sheets have multiple choices to one question. All the options to same question are printed aside on the paper, forming a "block". All the blocks's locations, sizes and numbers of options given are enough to save it to XML file. Location is recorded according to a coordinate system, usually followed in .NET i.e. upper left corner as O(0,0) (x,y) +ive x asis towards right side, +ive y towards bottom.

To read a specific block in the sheet, (sheet means the extracted sheet in the first section), OMR.OpticalReader.getScoreOfSheet can be called. This method executes the above procedure repeatedly to read all the lines in all of the 4 BigAnswerBlocks printed on the sheet.

Reading The Selected Option Out of the Given Choices

When a multiple choice selection block is sliced out of the document it's time to read the selected choice. For reading, the block is divided into as many equal parts as there are options present in it. Then the image is converted to binary, based on the mean color of the block. This is how we convert white papers to pure white and more than half the ink-filled pixels to pure black.

The black pixel count is recorded on each subdivision of block.

The darkest block is compared with other blocks and if a remarkable difference exists between the two sub divisions, the darker one is recorded as "Marked". Depending upon the number of Marked choices it can be decided which option was selected.

Note

Take a look at the other methods also. The methods can read all the choices from a single paper sheet in one method call, and create an XML specification sheet for two kinds of sheets given.

The heart of the camera image sheet recognizer lies in the following method.

Points of Interest

Now, what's next is to make an application that takes a Folder full of answer sheets for a test paper conducted in a class of 50 students or more. Or, have the address of a scanner attached to a PC and one after another start processing images. Depending upon the registration number written on sheet, the program should create an XLS file a PDF so that result is compiled totally electronically.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

umar.techBOY
Engineer techCREATIONS
Pakistan Pakistan
Developer, Programmer, Beta Tester; technically, i'm none of these. I'm a mechanical engineer, programming is my passion, my hobby and my amateur non profit profession. I program when ii need and innovate whenever, wherever i want.
 
Learned:
C#
 
Mixed:
C#+Applied Mathematicss-Robotics+C++
 
Developed:
C# OMR Reader
Monopoly (Urdu language)
HybridAutomation Framework
SMS Bomber (Windows Mobile 6 Professional)
Hard disk watch tower
Farmville Super Clicker
Games Profile selector
Windows mobile salat reminder
Windows mobile SMS Pole Host
and alot of other small apps
Follow on   Google+

Comments and Discussions

 
QuestionVB.Net Convert? Pinmemberferhat_131-Jan-13 7:42 
AnswerRe: VB.Net Convert? Pinmemberumar.techBOY22-Feb-13 4:21 
QuestionExtraction Failed Pinmemberchegs_pro26-Jan-13 2:03 
AnswerRe: Extraction Failed Pinmemberumar.techBOY22-Feb-13 4:14 
QuestionSame project with scaned images PinmemberMirasab7-Dec-12 3:30 
AnswerRe: Same project with scaned images Pinmemberumar.techBOY22-Feb-13 4:16 
AnswerRe: Same project with scaned images Pinmemberumar.techBOY13-Jun-13 19:46 
Questionplease help Pinmemberexpe304-Dec-12 23:25 
AnswerRe: please help Pinmemberumar.techBOY6-Dec-12 6:09 
AnswerRe: please help Pinmemberumar.techBOY13-Jun-13 19:48 
QuestionModifying with 160 Questions PinmemberAhmad Fahim Tokhi21-Nov-12 20:57 
AnswerRe: Modifying with 160 Questions Pinmemberumar.techBOY22-Feb-13 4:19 
AnswerRe: Modifying with 160 Questions Pinmemberumar.techBOY13-Jun-13 20:10 
Questionsheets.xml query [modified] Pinmemberkeencoder10-Nov-12 21:01 
can you help me to create my own settings on sheets.xml.
Or can you provide a documentation on how to create.
 
Another thing, base on your sample "DSC_0012.jpg", there are 4 image on left and right sides which is (lc/rc). my question is, what if my scanned answer sheet has no circle image (lc/rc).
What will happen?
 
Thanks
 
-James

modified 11-Nov-12 5:57am.

AnswerRe: sheets.xml query Pinmemberumar.techBOY12-Nov-12 1:28 
GeneralRe: sheets.xml query Pinmemberkeencoder12-Nov-12 3:44 
GeneralRe: sheets.xml query Pinmemberumar.techBOY13-Nov-12 3:19 
GeneralRe: sheets.xml query Pinmemberkeencoder14-Nov-12 8:23 
AnswerRe: sheets.xml query Pinmemberumar.techBOY12-Nov-12 1:32 
QuestionNot able to run Code on Visual Studio 2009 PinmemberMember 832112910-Nov-12 1:06 
AnswerRe: Not able to run Code on Visual Studio 2009 Pinmemberumar.techBOY10-Nov-12 2:39 
GeneralMy vote of 4 PinmvpKanasz Robert6-Nov-12 2:29 
QuestionBatch processing & Database Pinmemberspark855-Nov-12 13:53 
AnswerRe: Batch processing & Database Pinmemberumar.techBOY12-Nov-12 1:16 
GeneralRe: Batch processing & Database Pinmemberspark8513-Nov-12 12:46 
GeneralRe: Batch processing & Database Pinmemberumar.techBOY14-Nov-12 5:36 
GeneralRe: Batch processing & Database Pinmemberumar.techBOY14-Nov-12 5:45 
GeneralRe: Batch processing & Database Pinmemberspark8513-Nov-12 17:09 
GeneralRe: Batch processing & Database Pinmemberumar.techBOY14-Nov-12 5:16 
GeneralRe: Batch processing & Database Pinmemberumar.techBOY14-Nov-12 5:37 
GeneralRe: Batch processing & Database Pinmemberspark8520-Nov-12 7:22 
GeneralRe: Batch processing & Database Pinmemberumar.techBOY13-Jun-13 20:10 
QuestionReading in standard omr sheet Pinmemberrush2rajiv23-Oct-12 0:44 
AnswerRe: Reading in standard omr sheet Pinmemberumar.techBOY12-Nov-12 1:30 
QuestionTo call the getScreOfSheet, how do I code? Pinmemberkaz_panda16-Oct-12 3:21 
AnswerRe: To call the getScreOfSheet, how do I code? Pinmemberumar.techBOY16-Oct-12 6:00 
GeneralRe: To call the getScreOfSheet, how do I code? Pinmemberkaz_panda16-Oct-12 11:41 
GeneralRe: To call the getScreOfSheet, how do I code? Pinmemberumar.techBOY18-Oct-12 9:06 
GeneralRe: To call the getScreOfSheet, how do I code? Pinmemberkaz_panda18-Oct-12 11:02 
QuestionHow can i can with a sheet A4, 100 questions Pinmemberquantrimangvn1-Oct-12 5:24 
Answer3Re: How can i can with a sheet A4, 100 questions [modified] Pinmemberumar.techBOY3-Oct-12 1:59 
GeneralRe: 3Re: How can i can with a sheet A4, 100 questions [modified] Pinmemberquantrimangvn3-Oct-12 2:44 
GeneralRe: 3Re: How can i can with a sheet A4, 100 questions Pinmemberumar.techBOY3-Oct-12 4:34 
GeneralRe: 3Re: How can i can with a sheet A4, 100 questions Pinmemberquantrimangvn3-Oct-12 15:57 
GeneralRe: 3Re: How can i can with a sheet A4, 100 questions PinmemberAhmad Fauzi1-Dec-12 14:56 
GeneralRe: 3Re: How can i can with a sheet A4, 100 questions Pinmemberumar.techBOY2-Dec-12 3:56 
GeneralRe: 3Re: How can i can with a sheet A4, 100 questions PinmemberAhmad Fauzi2-Dec-12 13:55 
GeneralRe: 3Re: How can i can with a sheet A4, 100 questions Pinmemberumar.techBOY13-Jun-13 19:49 
GeneralRe: 3Re: How can i can with a sheet A4, 100 questions Pinmemberumar.techBOY13-Jun-13 20:09 
GeneralRe: 3Re: How can i can with a sheet A4, 100 questions PinmemberArden Jeric Macapuno22-Feb-13 20:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140415.2 | Last Updated 20 Aug 2013
Article Copyright 2012 by umar.techBOY
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid