error in corr2 function in matlab
古いコメントを表示
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=imread('1.png');
one=imresize(one,[42 24]);
two=imread('2.png');
two=imresize(two,[42 24]);
three=imread('3.png');
three=imresize(three,[42 24]);
four=imread('4.png');
four=imresize(four,[42 24]);
five=imread('5.png');
five=imresize(five,[42 24]);
zero=imread('0.png');
zero=imresize(zero,[42 24]);
sign=imread('sign.png');
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
load NewTemplates1 % Loads the templates of characters in the memory.
snap=imread('untitled.png');
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 件のコメント
Mansi Sharma
2020 年 10 月 4 日
can you please provide me the correct code for this ? I'm getting same problem.
wiqar Ahmad
2021 年 2 月 5 日
can you please share me the correct code?
Will be Thankfull
Walter Roberson
2021 年 2 月 5 日
As discussed below: use rgb2gray() before doing the corr2.
採用された回答
その他の回答 (1 件)
John BG
2018 年 1 月 15 日
編集済み: John Kelly
2018 年 1 月 16 日
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=imread('1.png');one=one(:,:,1);
% one=imresize(one,[42 24]);
two=imread('2.png');two=two(:,:,1);
% two=imresize(two,[42 24]);
three=imread('3.png');three=three(:,:,1);
% three=imresize(three,[42 24]);
four=imread('4.png');four=four(:,:,1);
% four=imresize(four,[42 24]);
five=imread('5.png'); five=five(:,:,1);
% five=imresize(five,[42 24]);
zero=imread('0.png');zero=zero(:,:,1);
% zero=imresize(zero,[42 24]);
sign=imread('sign.png');sign=sign(:,:,1);
% 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
load NewTemplates1 % Loads the templates of characters in the memory.
snap=imread('untitled.png');snap=snap(:,:,1);
% 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 件のコメント
SHOBA MOHAN
2018 年 1 月 15 日
Walter Roberson
2018 年 1 月 15 日
Extracting just the red channel from each png is not very useful in locations such as Ontario Canada, or California USA, which mostly use blue license plate numbers and letters for non-commercial vehicles (in Ontario, diplomatic plates are white font and commercial vehicles are black font.)
Walter Roberson
2018 年 1 月 15 日
編集済み: John Kelly
2018 年 1 月 16 日
In my country, current personal license plate texts are:
- British Columbia: blue
- Alberta: red
- Saskatchewan: green
- Manitoba: blue
- Ontario: blue
- Quebec: blue
- Nova Scotia: blue
- New Brunswick: red
- Prince Edward Island: light brown as of 2013 but green for decades before that so most would be green
- Newfoundland and Labrador: blue as of 2007, but red for the 14 years before that so a mix would be expected
- Yukon: black
- Northwest Territories: blue
- Nunavut: black
So your version would work with Alberta; New Brunswick; some older Newfoundland and Labrador that would not be rare; Yukon; Nunavut; and a small minority of Prince Edward Island. In terms of population: somewhere on the order of 15% to 20%, I estimate.
Walter Roberson
2018 年 1 月 15 日
The rules about license plates on the front of cars are provincial in Canada, so some provinces require them and some do not.
John BG
2018 年 1 月 16 日
Thanks again for this other clarification :)
カテゴリ
ヘルプ センター および File Exchange で Template Matching についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!