Problem With Vehicle number plate detection code.

4 次查看(过去 30 天)
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
A=imread('alpha/A.bmp');B=imread('alpha/B.bmp');C=imread('alpha/C.bmp');
D=imread('alpha/D.bmp');E=imread('alpha/E.bmp');F=imread('alpha/F.bmp');
G=imread('alpha/G.bmp');H=imread('alpha/H.bmp');I=imread('alpha/I.bmp');
J=imread('alpha/J.bmp');K=imread('alpha/K.bmp');L=imread('alpha/L.bmp');
M=imread('alpha/M.bmp');N=imread('alpha/N.bmp');O=imread('alpha/O.bmp');
P=imread('alpha/P.bmp');Q=imread('alpha/Q.bmp');R=imread('alpha/R.bmp');
S=imread('alpha/S.bmp');T=imread('alpha/T.bmp');U=imread('alpha/U.bmp');
V=imread('alpha/V.bmp');W=imread('alpha/W.bmp');X=imread('alpha/X.bmp');
Y=imread('alpha/Y.bmp');Z=imread('alpha/Z.bmp');
%Natural Numbers
one=imread('alpha/1.bmp');two=imread('alpha/2.bmp');
three=imread('alpha/3.bmp');four=imread('alpha/4.bmp');
five=imread('alpha/5.bmp'); six=imread('alpha/6.bmp');
seven=imread('alpha/7.bmp');eight=imread('alpha/8.bmp');
nine=imread('alpha/9.bmp'); zero=imread('alpha/0.bmp');
%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
function letter=readLetter(snap)
load NewTemplates
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
im1 = imread('BluePN.JPG');
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);
Iprops=regionprops(im,'BoundingBox','Area', 'Image'); %read letter
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.
  4 个评论
yanqi liu
yanqi liu 2022-1-11
yes,sir,may be add the m files and images to zip file,then upload the zip file,so we make some debug
Matt Alvarez
Matt Alvarez 2022-1-11
ah yes i will edit the post again to add the zip file. Thank you for your comment!

请先登录,再进行评论。

采纳的回答

Harikrishnan Balachandran Nair
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!

更多回答(0 个)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by