i am having problem in reading scanned images in OMR Project
    3 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
clc; close all; clear all; %directory from reference pics are selected original = rgb2gray(imread('C:\Users\Sabir Malik\Documents\MATLAB\.jpg')); srcFiles = dir('C:\Users\Sabir Malik\Documents\MATLAB\Project\img295.jpg'); %Colomns name in Mircosoft Excel Save File T={'Roll no','score','status'}; sheet=1; %specifyig excel sheet number % cR='E1'; xlswrite('result.xls',T,sheet) %matlab function to write result in excel len=length(srcFiles); %matlab function to get lentgh of all images files scr=zeros(len,1); %making score lentgh to zeros initially sts=zeros(len,1); %making status zeros initially
for khi = 1 : len %for loop from 1 to lentgh of all images filename = strcat('C:\Users\Sabir Malik\Documents\MATLAB\Project\',srcFiles(khi).name); %getting file path I2=rgb2gray(imread(filename)); %converting rgb image to gray using matlab function %figure,imshow(I); [I3]=imageRegistration(original,I2);
    I4 = imresize(I3, [631 489]);
    [I]=imageRegistration(original,I4);
    options='ABCD';                 % Options of OMR sheet
    ans='';                         % This string stores the options entered by the student
    key='C C C C B B D D A A C C A A D D B B B C '; % This string contains correct answers
    x=99;                           % x-coordinate of first bubble
    y=200;                          % y-coordinate of first bubble
    s=37;                           %spacing between each bubble
    sr=32;                          %spacing between consecutive rows
    for i=1:10                      %for loop for getting result of first 10 blobs      
       sy=y+(i-1)*sr;
       for j=1:4                    %for loop for recognizing 4 blobs colomn wise
       sx=x+(j-1)*s;
       %  disp(sx);
       %  disp(sy);
       %  disp(I(sy,sx));
        if((I(sy,sx)<25))        
          c(i,j)=0;
        else
         c(i,j)=1;    
        end
       end
    end
    %Same process for the other half
    x=289; % x-coordinate of first bubble in other half
    y=200; % y-coordinate of first bubble in other half
    for i=11:20                   %for loop for next 10 blobs            
       sy=y+(i-11)*sr;
       for j=1:4                  %for loop for next 10 blobs 4 colomns
         sx=x+(j-1)*s;
        %  disp(sx);
        %  disp(sy);
        %  disp(I(sy,sx));
         if((I(sy,sx)<25))
             c(i,j)=0;
         else
             c(i,j)=1;
         end
       end
    end
    %printing the results in the string
    for i=1:20                          %for loop for priinting all 20 blobs result                           
       m=0;
      for j=1:4                                          
         if(c(i,j)==0)                                     
            ans=[ans ' ' options(j)];  %handFill blob values is recognized and check from options
         else
            m=m+1;                  
         end
      end
      if(m==4)                                           
         ans=[ans ' NONE'];            %if no blob is filled None is values marked
      end
    end
   score=0;
   disp(ans);
   for i=1:20
       [token,remain]=strtok(ans);     %strtok function psses string from left to right to token 
       [ktoken,kremain]=strtok(key);   %if any space is found in str it will be pushed in remain as delimeter
       if(token==ktoken)               %compare ans token with given correct key token if it matches
           score=score+1;              % scores are incremented by one otherwise remains same
       end
       ans=remain;
       key=kremain;
   end
   disp('You have scored : ')
   disp(score);
   if(score==20)                       %if else condition for status of OMR Sheet
      status=sprintf('pass');
   else
      status=sprintf('fail');
   end
   scr(khi,1)=score;
  if (status == 'pass')
      T1={'pass'};
  else
      T1={'fail'};
  end
roll=['CS1410' num2str(khi)]        %giving registration number to each student serial wise
T2={roll}
cR2=sprintf('A%d',khi+1);           %sprintf function prints each value row wise                         
xlswrite('result.xls',T2,1,cR2)     %writing Status in Excel sheet
cR1=sprintf('C%d',khi+1);
xlswrite('result.xls',T1,1,cR1)     %writing registration number in Excel sheet
%h = msgbox(['You scored ' num2str(score) 'marks' '    ' ' RESULT : ' status], 'Test Result');
end
cR='B2';
xlswrite('result.xls',scr,1,cR) %writng score obtained in excel sheet
    /matlabcentral/answers/uploaded_files/66917/img294.jpg>>
Risposte (0)
Vedere anche
Categorie
				Scopri di più su Import, Export, and Conversion in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

