error in vehicle number extraction
2 次查看(过去 30 天)
显示 更早的评论
I wish to extract the number and sign (person with disability) from vehicle number plate. I created the template for the same. I am able to extract the number plate but failed in extracting the characters from the image got the error "index exceeds matrix dimension".
%Templates Creation
desiredsize = [42 24];
files = {'1', '2', '3', '4', '5', '0', 'sign'};
NewTemplates1 = cell(size(files));
for fileidx = 1:numel(files)
img = imread([files{fileidx}, '.png']);
img= rgb2gray(img);
img = imresize(img, desiredsize);
NewTemplates1{fileidx} = img;
end
%number plate extraction code
img=imread('2222.jpg');
figure,imshow(img);
load NewTemplates1;
% load('imgfildata.mat');
[~,cc]=size(img);
picture=imresize(img,[300 500]);
if size(picture,3)==3
picture=rgb2gray(picture); %grey values are btwn 0 to 1 or 0 to 255
end
threshold = graythresh(picture); %greythresh gives the threshold value of greyscale image
picture =~im2bw(picture,threshold); %black nd white values are 0 or 1 and values greater thn threshold=1,rest=0 and invert white and black ie 1 to 0 and 0 to 1
picture = bwareaopen(picture,30); % those things that have less than 30 pixels are removed
if cc>2000
picture1=bwareaopen(picture,3500); %those things that have less than 3500 pixels are removed ie excluding nmbr plate
else
picture1=bwareaopen(picture,3000); %those things that have less than 3000 pixels are removed ie excluding nmbr plate
end
picture2=picture-picture1; %only number plate is left
picture2=bwareaopen(picture2,50); %only text is there in the nmbr plate
figure,imshow(picture2);
title('plate extracted');
[L,Ne]=bwlabel(picture2); %l gives matrix which has info of nmbr plate and Ne gives number of digits or characters
final_output=[];
t=[];
for n=1:Ne
[r,c] = find(L==n);
n1=picture(min(r):max(r),min(c):max(c)); %picture command crops nth object from L
n1=imresize(n1,[42,24]); %in database size is 42,24 so it is resized so that we can match it with the database
figure,imshow(n1);
x=[ ];
for k=1:length(NewTemplates1)
% totalLetters
y=corr2(NewTemplates1{1,k},n1);
x=[x y];
end
% t=[t max(x)];
if max(x)>0.35
z=find(x==max(x));
out=cell2mat(NewTemplates1(2,z));
final_output=[final_output out];
end
end
np=final_output;
disp(np);
I am attaching the input and templates files for your kind reference. Can anyone help me on this issue and suggest me how to extract the no.s and sign successively.
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!