Sie sind auf Seite 1von 16

Bangladesh University of Engineering and Technology

Course Number: EEE 212


Course Name: Numerical Technique Laboratory

Report on
“OMR Sheet Evaluation Toolbox Using MATLAB”

Submitted to:
Md. Mukhlasur Rahman Tanvir
Mohammad Tariqul Islam

Submitted by
Md. Mehedi Hossen Limon (Student ID- 1406059)
Fariba Islam (Student ID- 1406060)

Department: EEE
Section: A-2
Level 2; Term 2

Date of Submission: 17 December, 2016

1
December 17, 2016
Md. Mukhlasur Rahman Tanvir
Mohammad Tariqul Islam
Department of Electrical and Electronic Engineering
BUET

Subject: Submission of report on “OMR Sheet Evaluation Toolbox Using MATLAB”

Dear Teachers,
We have the pleasure to present the report on “OMR Sheet Evaluation Toolbox Using
MATLAB”. We would like to take this occasion to express our sincere gratitude to you for
giving us such an opportunity to make a report which has enhanced our knowledge on such an
important software like MATLAB whose use is almost inevitable in engineering world.
OMR sheets are used to answer MCQs of different examinations here we tried to make an OMR
sheet evaluation toolbox so that without requiring an OMR reader one would be able to check
OMR sheets easily.

We tried our best to explain our project in this report as far as possible. But limitation of time
restrained us to make it as illustrative as it should be. Yet we think this report will help the readers
to understand how this project will come into use.
Thank you for your consideration.

Faithfully Yours,
Md. Mehedi Hossen Limon
Student ID- 1406059
Fariba Islam
Student ID- 1406060
Section: A-2
Level-2, Term 2
Department: EEE;

2
Abstract:
MCQs are very common type of questions nowadays. These MCQs are answered in OMR
sheets. Checking these sheets require an OMR reader which is large and money needs to be spent
to buy it.
The aim of this project is to develop a code in MATLAB using which OMR sheets can be
checked using PC. Effort has been given to make this application user-friendly and as less time
consuming as possible.
A graphical user interface is introduced to make the application user friendly. One would need to
load the solution of the question paper and the scanned image of the answer script to evaluate the
answer script. The actual script needs to be scanned, image of photocopied script results in error.

3
Contents

1. Introduction .................................................................................................................................... 5

2. Methodology .................................................................................................................................... 5
2.1loading and working with the solution of the question and image of the answer script ..................... 5

2.2 Functions & Variables .................................................................................................................. 6

2.3 Determination of the answer given to each question and evaluation ........................................ 7
2.4 Graphical User Interface (GUI) .................................................................................................... 7

3. Result ............................................................................................................................................... 8

4. Summary and conclusion ............................................................................................................... 9

5. The code .......................................................................................................................................... 9

4
1. Introduction:
Nowadays multiple choice questions (MCQs) are inevitable part of almost all examinations.
Even in admission tests of different schools, colleges and universities a significant part of the
question paper comprises of MCQs. Checking MCQs manually would have been a tiring and
troublesome task for human beings and that is why OMR sheets were invented. This sheet can be
scanned and read by an OMR reader to find out the marks obtained by the students. In this
project it was aimed to make an OMR reader using MATLAB to lessen the requirement of
needing an OMR reader for checking the MCQs, rather having a PC with MATLAB installed
will be enough for that purpose. This will help to digitalize the education system even more.
Because the students can fill up the scanned image of the blank OMR sheet in Microsoft paint or
other such software and email it to the examiner the examiner can then easily check the script
using this program. Even students can use it for self-assessment.
Here we introduced GUI to make the OMR reader easier to use.

2. Methodology

2.1 loading and working with the solution of


the question and image of the answer script
First of all the solution of the question is
stored in an excel file. Then the answer script
of the student is scanned and this scanned
image (Figure 1) is saved in the directory
where the m file is saved. This image is
converted to grayscale in MATLAB using the
built-in function rgb2gray.
The OMR sheet that we used has 4 sections
and each section has 15 sets of answers.
This grayscale image is then opened with
imtool and magnified until each pixel
becomes visible; in this case it is needed to be
magnified 800 times (Figure 2).
From the imtool feature the x and y
coordinate of each pixel can be determined
and the intensity of each pixel can also be
found out.

Figure 1: scanned script

5
Once the image is loaded the program check whether the four black points at four corners have
their centers at the correct places if not an error message is shown.
If the solution uploaded is not in .xls or .xlsx format or if it is blank then again an error message
is shown.

Figure 2: image of a single circle magnified 800 times

2.2 Functions & Variables


Four functions are used in the code. The function finalproject is the base function.for the GUI
window. This function and its sub-functions control functionality of the GUI.
When a scanned image is loaded, the is_img_ok function is called and returns whether the image
can be evaluated or not. This function finds whether the black blocks in the four corner of the
omr is in their place or not and thus determines if omr circle’s co-ordinates are right or wrong. If
wrong the functions returns and gives an error message.
If the scanned can be evaluated, the finalver7 function is called. This function takes the Image,
number of question and solution and returns roll, marks, test id and remarks. The omr has 4
sections and 15 mcq in each section. In a particular section, the distance of y value between the
center of first circle of the two consecutive mcq is set as the ‘diffrow’ variable. For a particular
question the distance of x value between the center of two consecutive circle is set as the ‘diffcol’
variable. The distance of x value between first circle of first mcq of two consecutive section is
set as diffsection.
The function blackpixelcounter takes the x and y coordinate value of the center pixel of a circle,
and returns number of black pixel and total pixels. For a circle, as the x and y co-ordinate value
of pixel cannot be fractional, the radius is not same all over the circle. So the pixel number is
counted manually.

6
2.3 Determination of the answer given to each question and evaluation
From the magnified view it was found that there are 12 pixels within the length ‘h’ which is
considered the width of first pixel column stored in newwidy variable. As it goes ahead along the
diameter parallel to the x axis the height of pixel column increases and after certain period it
becomes fixed. Then at a certain position the height of pixel column started to decrease and
returns to the starting value at the end of the diameter.
A pixel is counted as black if its intensity is below a certain value stored in ‘t’ variable. This is
called threshold intensity value. In this case, the threshold intensity 200 is considered. The total
pixel number, n and black pixel number, totpix are counted by considering each pixel column
along the diameter parallel to x axis.
By accessing each mcq, the circles of the mcq is sent to the blackpixelcounter function which
returns number of black pixel and total pixel in a circle. If the number of black pixel is greater
than a specified percent of total pixel, the circle is considered filled. If filled, the letter related to
that circle is compared with the solution of that question. Mark will be added if the answer is
right. When more than one option is filled in a mcq, the mark of that answer is considered
uncountable.

2.4 Graphical user interface (GUI):


The layout of the interface is as
shown in the figure. 6 pushbuttons
are used here, one edit text , one axes
and 10 static texts.
By pressing the Help button the user
gets informed about how to use the
interface and evaluate the script.
By pressing the load OMR button the
user loads the image of the answer
script. Then the solution is to be
loaded by pressing the ‘Load
Solution’ button.
If the examiner wants he can check
the first fixed number of questions
instead of checking all of them. And
the number has to be entered under
the ‘How many Questions’ text.
Figure 3: layout of the GUI

7
3. Result:
Once the user loads the image
and the solution and the number
of questions, the Roll of the
student his or her marks, Test ID
and any remarks regarding the
marks appears in the
corresponding box. The loaded
image appears in the axes.
It takes a few seconds for the
output to appear.
If one fills up the correct answer
containing circle he gets one
mark and if wrong answer is
given or more than one circle is
filled then the student scores Figure 4: output in the GUI
zero for that question. The
output comes as shown in figure 4.

If help is pressed then the output that


appears is shown in figure 5

Figure 5: the output of pressing help


8
4. Summary and conclusion:
Since MCQs have become very common in many examinations due to development of
OMR there is an increasing demand of OMR readers among institutions and teachers. In
this project a code is developed to check OMR sheets and evaluate them to reduce the
need of an OMR reader.
The code used in this project checks the number of circles filled up by the student per
question and the answer corresponding to that filled up circle, however if more than a
single circle is filled up for a single MCQ then student scores zero for that question. The
total correct answer is found out and corresponding marks are given as output. GUI was
used here for taking image and solution input and for giving the marks as output.
More improvements it for example making it work for any kind of OMR sheet, reduce
the time requirement for the code. Also, for slight change in position or quality of the
scanned image the code does not work so improvement is necessary to make it more
flexible.
Requirements. The hardware required for using this program is a scanner and a pc and
the software necessary is MATLAB (we have tested for 2012a edition onwards)

5. The code
Function For GUI:

6. function varargout = finalproject(varargin)


clc
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @finalproject_OpeningFcn, ...
'gui_OutputFcn', @finalproject_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end

9
function finalproject_OpeningFcn(hObject, eventdata, handles, varargin)

handles.output = hObject;

guidata(hObject, handles);

function varargout = finalproject_OutputFcn(hObject, eventdata, handles)


varargout{1} = handles.output;
axes(handles.axes1);
imshow('C:\Users\ASUS\Desktop\Final\OMR IMAGE\restartimage.png');

function load_image_Callback(hObject, eventdata, handles)

[path,user_cance]=imgetfile();
if user_cance
return
end
im=rgb2gray(imread(path));
siz = size(im);

if siz(1)==0 || siz(2)==0 || siz(1)<3000 || siz(2)<2400


msgbox(sprintf('Error!! You have Selected Wrong image!'),'Error','Error');
return
end
ok = is_img_ok(im);
if ~ok
msgbox(sprintf('Error!This OMR can not be evaluated! Please
Restart!'),'Error','Error');
return;
end

handles.im = im;

axes = handles.axes1;
imshow(handles.im);
guidata(hObject,handles);

function qno_Callback(hObject, eventdata, handles)

function qno_CreateFcn(hObject, eventdata, handles)


if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function evaluation_Callback(hObject, eventdata, handles)

qu_no = str2num(get(handles.qno,'String'));
[marks,Remark,Roll,Test] = finalver7(handles.im,handles.solution,qu_no);
handles.marks = marks;

10
set(handles.mark,'String',num2str(marks))
handles.Roll = Roll;
set(handles.remarks,'String',Remark)
handles.Remark= Remark;
set(handles.roll,'String',num2str(Roll))
handles.Test = Test;
set(handles.testid,'String',num2str(Test))
guidata(hObject,handles);

function about_Callback(hObject, eventdata, handles)


h = msgbox ({'Welcome to our OMR Sheet Evaluation Toolbox','','This is a project for
Numerical Technique Laboratory','','Course No. EEE 212','', ...
'We are:','','Md.Mehedi Hossen Limon','Student ID No. 1406059','','Fariba
Islam','Student ID No. 1406060','','Section:A2','', ...
'Department of Electrical & Electronic Engineering','','Bangladesh University of
Engineering & Technology','','Thank You!', ...
'','For Any Query or Advice','Feel free to email
at','mhlimon1995@gmail.com','ezqhaz@gmail.com'},'About');

function Help_Callback(hObject, eventdata, handles)

h = msgbox({'Here is our Help Window','Please read to solve your problem or to know what
you want!','','Load OMR','Click the Load Image button', ...
'a file open dialog box will open','Go to OMR Image folder in which the scanned
image of OMR sheets are stored', ...
'Select an image and click open.' ...
'','','In the input box give the number of question you want to evaluate(maximum
60)','','Load Solution','','Click the Load Image button', ...
'a file open dialog box will open.',' Go to OMR Solution folder in which the
solution excel file of OMR sheets are stored.', ...
'Select a file and click open.','','IF YOU CAN NOT SEE ANY FILE,THEN CHANGE THE FILE
TYPE TO *all files ','AND SELECT YOUR SOLUTION FILE.', ...
'NOTE THAT THIS FILES ARE EXCEL FILES.,','','click Evaluate OMR button and wait to
see roll,test id,marks,remarks in the specified field.', ...
'The Roll, marks,Test ID and Remarks are shown In the Specified Field', ...
'','','Click restart if any problem arises or you want to evaluate freshly.','','',
...
'Note: After first omr sheet evaluation', 'you can change the omr or the solution
according to your wish until you press restart button.', ...
'Hope, Your query is Satisfied!'},'HELP');

function load_solution_Callback(hObject, eventdata, handles)

[path,user_cance]=imgetfile();
if user_cance
return
end
[~,~,sol] = xlsread(path,'A1:A60');
solution = upper(char (sol));
handles.solution = solution;
guidata(hObject,handles);

11
function restart_Callback(hObject, eventdata, handles)

axes(handles.axes1);
imshow('C:\Users\ASUS\Desktop\Final\OMR IMAGE\restartimage.png');

set(handles.qno,'String','');
set(handles.mark,'String','')
set(handles.remarks,'String','')
set(handles.roll,'String','')
set(handles.testid,'String','')
guidata(hObject,handles);

Function For OMR Compatibility:

function oka =is_img_ok(I)


% This function evaluates if an image of an omr sheet can be evaluated or not
% Inputs:
% I = grayscale image of an omr sheet
% Outputs:
% oka = return 1 if can be evaluated , 0 otherwise
t =200;
blackblock = 0;

xwid = 22;
ywid = 22;
for l = 1:4
if l == 1
startx= 128;
starty = 261;
elseif l==2
startx = 2324;
starty = 264;
elseif l==3
startx = 130;
starty = 3214;
elseif l==4
startx = 2325;
starty = 3215;
end

synew = starty;
sxnew = startx;
n = 0;total =0;
for i = 1:xwid
for j = 1:ywid

12
a = I(synew+j-1,sxnew+i-1);
if a<=t
n = n + 1;
end
total = total + 1;
end
end
if n>=.4*total
blackblock = blackblock +1;
end
end
if blackblock ==4
oka =1;
else
oka =0;
end

end

Function For Evaluation of an OMR Sheet Image:

function [mark,remarks,Roll,TD]=finalver7(I,solution,num)
% Function: finalver7
% Written By-
% Md. Mehedi Hossen Limon
% Fariba Islam
% Department of Electrical & Electronic Engineering
% Bangladesh University of Engineering and Technology
%
% Inputs :
% I = image file
% solution = a xlsx solution file
% num = number of question
% Outputs:
% mark = Total Correct answer
% remarks = Comment on the Result
% Roll = Roll of the examinee
% TD = Test ID

diffcol = 57;
diffrow = 116;
diffsection = 462;
solution = solution(1:num);
if length(solution)==0
msgbox(sprintf('Error!! Please Restart!'),'Error','Error');
return
end

13
p = .6;
str = 'ABCD';

c = zeros(num,5);
c(:,1) = 1:num;
mark = 0;
R = zeros(10);
Roll = 0;
T = zeros(10,3);
TD = 0;

% for MCQ
for k = 1:num

count = (k<=15) + 2*(k>=16&&k<=30)+3*(k>=31&&k<=45)+ 4*(k>45);


startx = 487; starty = 1488;
startx = startx+(count-1)*diffsection;
sy = starty + ((k-((count-1)*15)-1))*diffrow;
for l = 1:4
sx = startx + (l-1)*diffcol;
[n,total] = blackpixelcounter(I,sx,sy);
if n>= p*total
c(k,l+1) = 0;
Result= str(l);
% check right answer;
if Result== solution(k)
mark = mark + 1;

end

else
c(k,l+1) = 1;
end
% check double fill ;
if l == 4
dob = 0;markdouble = 0;
for a = 1:l
if c(k,a+1) == 0
dob = dob+1;
if Result == solution(k)
markdouble = markdouble +1;
end
end
end
if dob>1 && markdouble ~=0
mark = mark -1;
disp('double')
end
end

end
end

% for roll

14
for k = 1:10

startx = 256;starty = 737;


diffrow = 57;
sy = starty +(k-1)*diffrow;
for l = 1:10
sx = startx + (l-1)*diffcol;
[n,total] = blackpixelcounter(I,sx,sy);
if n>= p*total
R(k,l) = 0;
if k ~=10
Roll = Roll + k*10^(9-(l-1));
end
else
R(k,l) = 1;
end
end
end

% for test id
for k = 1:10

startx = 949;
starty = 737;diffrow = 57;
sy = starty +(k-1)*diffrow;

for l = 1:3
sx = startx + (l-1)*diffcol;
[n,total] = blackpixelcounter(I,sx,sy);
if n>= p*total
if k ~= 10
TD = TD + k*10^(2-(l-1));
end
else
T(k,l) = 1;
end
end
end
if(mark>=floor(.33*num))
status='Great! Passed!';
else
status='Sorry! Failed! Need Improvement';
end
remarks = status;

end

15
Function for Pixel Counting of a circle:

function [ black,total] = blackpixelcounter(I,startx,starty)


% Funtion: Blackpixelcounter
% This funtion returns number of black pixel and total pixel of a
% circle of the omr
% Inputs:
% I = gray image file of omr
% startx = x ordiante value of center of the circle
% starty = y coordinate value of center of the circle
% Outputs:
% black = number of black pixel in the circle
% total = number of total pixel in the circle
radius = 21;
diameter = 43;
sx = startx;
sxnew = sx - radius;
newwidy = 12;
totpix = 0;
n = 0;
t=200;

for i = 1:diameter

synew = starty - newwidy/2;


for j =1:newwidy
a = I(synew+j-1,sxnew+i-1);
if a<=t
n = n + 1;
end
totpix = totpix + 1;
end
if i<=4
newwidy = newwidy + 4;
elseif (i>4 && i<=11) || i == 15
newwidy = newwidy + 2;
elseif (i>32 && i<40) || i==27 || i==29
newwidy = newwidy - 2;
elseif i>=40
newwidy = newwidy - 4;
end
end
black = n;
total = totpix;

end

16

Das könnte Ihnen auch gefallen