Why it is showing error?
Afficher commentaires plus anciens
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(find(rec == max(rec)));
% 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
.png)
Réponses (1)
Geoff Hayes
le 11 Oct 2019
Kartikey - there appears to be a hidden character at your line 70 which is the "blank" line in
% Numerals listings.
elseif ind == 34
If, on Linux, I do a cat -t readLetter.m, I see a question mark at the blank line
elseif ind == 33
letter = 'Z';
?
% Numerals listings.
elseif ind == 34
Just delete the blank line and the line with the comment to ensure that this special character is removed.
7 commentaires
Terry Lim
le 26 Mai 2020
Hi, Geoff Hayes
I am facing a problem which almost similar to his/her code. Which my error is:
Not enough input arguments.
Error in Letter_detection (line 4)
snap=imresize(snap,[42 24]);
below is the code for detect letter:
function letter=Letter_detection(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
For the template creation. The code is shown as below:
%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
I had tried my best to solve this problem maybe there is some other things or method i havent tried. by grabbing this oppotunity, I hope you could help me to solve this problem.
Geoff Hayes
le 26 Mai 2020
Hi Terry - the error message
Not enough input arguments.
Error in Letter_detection (line 4)
snap=imresize(snap,[42 24]);
is indicating that you are not passing enough input arguments into imresize. But according to the documentation found at imresize, you are passing in the correct number of arguments so I'm not sure why this would be causing a problem. Do you have the Image Processing Toolbox and so have access to this function, or is it something that you have written yourself? At the command line type
which imresize -all
and copy and paste the results here. This will tell you where this function is defined within your environment.
Aliasgar Merchant
le 30 Juil 2020
Modifié(e) : Aliasgar Merchant
le 30 Juil 2020
Hi Geoff Hayes
on using which imresize -all, it shows
/MATLAB/toolbox/matlab/images/imresize.m
/MATLAB/toolbox/parallel/gpu/@gpuArray/imresize.m % gpuArray method
Could you possibly tell me what the error is. Thanks.
Geoff Hayes
le 1 Août 2020
Aliasgar - what is the error? What is the line of code that generates the error? Presumably you are calling imresize in some way...
Image Analyst
le 1 Août 2020
At this point I think we'd need you to upload all the BMP images in a zip file so we can run the code, because your call to imresize() looks correct.
JIAHONG LIM
le 10 Avr 2021
Hi GeiffHayes and Image Analyst, may I know why some letters need only 1 ind to determine but some need two? Thank you very much
if ind==1 || ind==2
letter='A';
elseif ind==3 || ind==4
letter='B';
elseif ind==5
letter='C';
Walter Roberson
le 10 Avr 2021
This is taken from https://circuitdigest.com/tutorial/vehicle-number-plate-detection-using-matlab-and-image-processing which has a mismatch between the template building code and the template data file.
The characters that have two entries are the ones that have a "hole" in them. In the first version of the template, the hole is empoty, and in the second version of the template, the hole is filled.
Catégories
En savoir plus sur Cell Arrays dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!