Problem With Vehicle number plate detection code.

20 views (last 30 days)
Hello, so im trying to use a vehicle number plate detection from Pankaj Katri, but there are errors to when i run it.
Here are the errors that showed and cant understand.
(this error came from running number 3 which is Plate_detection.m which the authors says to use to run the code)
Plate_detection
Brace indexing is not supported for variables of this type.
Error in Letter_detection (line 8)
cor=corr2(NewTemplates{1,n},snap);
Error in Plate_detection (line 34)
letter=Letter_detection(Iprops(i).Image); % Reading the letter corresponding the binary image 'N'.
you can easily find the website by searching "Car Number Plate Detection using MATLAB and Image Processing"
i am currently using the latest matlab which is R2021b
(the Zip is now included in this post)
Here the the three matlab codes that the author made
1. template_creation.m
%CREATE TEMPLATES
%Alphabets
%Natural Numbers
%Creating Array for Alphabets
letter=[A B C D E F G H I J K L M N O P Q R S T U V W X Y Z];
%Creating Array for Numbers
number=[one two three four five six seven eight nine zero];
NewTemplates=[letter number];
save ('NewTemplates','NewTemplates')
clear all
2. Letter_detection.m
snap = imresize(snap,[42 24]);
rec=[ ];
for n=1:length(NewTemplates)
cor=corr2(NewTemplates{1,n},snap);
rec=[rec cor];
end
ind=find(rec==max(rec));
display(ind);
% Alphabets listings.
if ind==1 || ind==2
letter='A';
elseif ind==3 || ind==4
letter='B';
elseif ind==5
letter='C';
elseif ind==6 || ind==7
letter='D';
elseif ind==8
letter='E';
elseif ind==9
letter='F';
elseif ind==10
letter='G';
elseif ind==11
letter='H';
elseif ind==12
letter='I';
elseif ind==13
letter='J';
elseif ind==14
letter='K';
elseif ind==15
letter='L';
elseif ind==16
letter='M';
elseif ind==17
letter='N';
elseif ind==18 || ind==19
letter='O';
elseif ind==20 || ind==21
letter='P';
elseif ind==22 || ind==23
letter='Q';
elseif ind==24 || ind==25
letter='R';
elseif ind==26
letter='S';
elseif ind==27
letter='T';
elseif ind==28
letter='U';
elseif ind==29
letter='V';
elseif ind==30
letter='W';
elseif ind==31
letter='X';
elseif ind==32
letter='Y';
elseif ind==33
letter='Z';
%*-*-*-*-*
% Numerals listings.
elseif ind==34
letter='1';
elseif ind==35
letter='2';
elseif ind==36
letter='3';
elseif ind==37 || ind==38
letter='4';
elseif ind==39
letter='5';
elseif ind==40 || ind==41 || ind==42
letter='6';
elseif ind==43
letter='7';
elseif ind==44 || ind==45
letter='8';
elseif ind==46 || ind==47 || ind==48
letter='9';
else
letter='0';
end
end
3. Plate_detection.m
imgray = rgb2gray(im1);
imbin = im2bw(imgray);
im = edge(imgray, 'prewitt');
%Below steps are to find location of number plate
Iprops1=regionprops(im,'BoundingBox','Area', 'Image');
area1 = Iprops1.Area;
count1 = numel(Iprops1);
maxa= area1;
boundingBox1 = Iprops1.BoundingBox;
for i=1:count1
if maxa<Iprops1(i).Area
maxa=Iprops1(i).Area;
boundingBox1=Iprops1(i).BoundingBox;
end
end
im = imcrop(imbin, boundingBox1);%crop the number plate area
im = bwareaopen(~im, 500); %remove some object if it width is too long or too small than 500
[h, w] = size(im);%get width
imshow(im);
count = numel(Iprops);
noPlate=[]; % Initializing the variable of number plate string.
for i=1:count
ow = length(Iprops(i).Image(1,:));
oh = length(Iprops(i).Image(:,1));
if ow<(h/2) && oh>(h/3)
letter=Letter_detection(Iprops(i).Image); % Reading the letter corresponding the binary image 'N'.
noPlate=[noPlate letter]; % Appending every subsequent character in noPlate variable.
end
end
Thank you for taking the time to read this.
Matt Alvarez on 11 Jan 2022
ah yes i will edit the post again to add the zip file. Thank you for your comment!

Hi Matt,
In the code that you have provided, the variable 'NewTemplates' is being stored as an array of images, which are of the same size. But, for calculating the 2D correlation coefficient , brace indexing is being used to access the array elements. This gives rise to error as NewTemplates is not stored as a 'cell array' . You can change it to the following line of code to avoid the error :
cor=corr2(NewTemplates(1,n),snap);
Hope this helps!