# error in corr2 function in matlab

14 Ansichten (letzte 30 Tage)
SHOBA MOHAN am 14 Jan. 2018
Kommentiert: Walter Roberson am 5 Feb. 2021
I have created templates of number and symbols and want to match the vehicle number plate with template using corr2 function. While running the code got the following error
Error using corr2
Expected input number 1, A, to be two-dimensional.
MAtlab code for template creation
%CREATE TEMPLATES
one=imresize(one,[42 24]);
two=imresize(two,[42 24]);
three=imresize(three,[42 24]);
four=imresize(four,[42 24]);
five=imresize(five,[42 24]);
zero=imresize(zero,[42 24]);
sign=imresize(sign,[42 24]);
number=[one two three four five zero ];
character=[number sign];
NewTemplates1=mat2cell(character,42,[24 24 24 24 24 24 24], 3);
save ('NewTemplates1','NewTemplates1')
clear all
matlab code for reading the letter
snap=imresize(snap,[42 24]); % Resize the input image so it can be compared with the template's images.
comp=[ ];
for n=1:length(NewTemplates1)
sem=corr2(NewTemplates1{1,n},snap); % Correlation the input image with every image in the template for best matching.
comp=[comp sem]; % Record the value of correlation for each template's character.
end
vd=find(comp==max(comp)); % Find the index which correspond to the highest matched character.
%*-*-*-*-*-*-*-*-*-*-*-*-*-
% Accodrding to the index assign to 'letter'.
% Alphabets listings.
if vd==1
letter='1';
elseif vd==2
letter='2';
elseif vd==3
letter='3';
elseif vd==4
letter='4';
elseif vd==5
letter='5';
elseif vd==6
letter='0';
elseif vd==7
letter='sign';
end
For kind information: The size of individual component in template is 42x24x3 uint8 and the input image also same dimension. Please provide the suggestion to do further.
##### 3 Kommentare2 ältere Kommentare anzeigen2 ältere Kommentare ausblenden
Walter Roberson am 5 Feb. 2021
As discussed below: use rgb2gray() before doing the corr2.

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

Walter Roberson am 14 Jan. 2018
You are asking corr2 to operate on a 42 x 24 x 3 array. That is a 3d array which is not something that corr2 can use. Your array is 3d because you are carrying through rgb. You need to do each plane independently, or you need to switch to greyscale, or you need to reshape so that you are working in 2d.
##### 1 KommentarKeine anzeigenKeine ausblenden
SHOBA MOHAN am 15 Jan. 2018
The code works fine after doing rgb2gray conversion. Thanks Walter

Melden Sie sich an, um zu kommentieren.

### Weitere Antworten (1)

John BG am 15 Jan. 2018
Bearbeitet: John Kelly am 16 Jan. 2018
Hi Shoba Mohan
Since the actual size of the input images, both the references and the unknown input to correlate with the references, I have omitted the imresize lines.
With that, one way to have your code running is as follows:
clear all;clc
% one=imresize(one,[42 24]);
% two=imresize(two,[42 24]);
% three=imresize(three,[42 24]);
% four=imresize(four,[42 24]);
% five=imresize(five,[42 24]);
% zero=imresize(zero,[42 24]);
% sign=imresize(sign,[42 24]);
number=[one two three four five zero ];
character=[number sign];
NewTemplates1=zeros([size(one) 7]);
% mat2cell(character,42,[24 24 24 24 24 24 24], 3);
NewTemplates1(:,:,1)=one;
NewTemplates1(:,:,2)=two;
NewTemplates1(:,:,3)=three;
NewTemplates1(:,:,4)=four;
NewTemplates1(:,:,5)=five;
NewTemplates1(:,:,6)=zero;
NewTemplates1(:,:,7)=sign;
save ('NewTemplates1','NewTemplates1')
clear all
% snap=imresize(snap,[42 24]); % Resize the input image so it can be compared with the template's images.
comp=[ ];
[sz1 sz2 sz3]=size(NewTemplates1);
for n=1:sz3
sem=corr2(NewTemplates1(:,:,n),snap); % Correlation the input image with every image in the template for best matching.
comp=[comp sem]; % Record the value of correlation for each template's character.
end
[vd,col,q]=find(comp==max(comp)); % Find the index which correspond to the highest matched character.
%*-*-*-*-*-*-*-*-*-*-*-*-*-
% Accodrding to the index assign to 'letter'.
% Alphabets listings.
if vd==1
letter='1';
elseif vd==2
letter='2';
elseif vd==3
letter='3';
elseif vd==4
letter='4';
elseif vd==5
letter='5';
elseif vd==6
letter='0';
elseif vd==7
letter='sign';
end
Now the code doesn't return error but the correlation doesn't catch some of the samples I have used.
Wouldn't it be reasonable to consider already working MATLAB application for car plate recognition, like:
.
thanks in advance for time and attention
John BG
##### 5 Kommentare4 ältere Kommentare anzeigen4 ältere Kommentare ausblenden
John BG am 16 Jan. 2018
Thanks again for this other clarification :)

Melden Sie sich an, um zu kommentieren.

### Kategorien

Find more on Region and Image Properties in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by