-
Notifications
You must be signed in to change notification settings - Fork 0
/
number_plate_det.m
134 lines (124 loc) · 2.36 KB
/
number_plate_det.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
clc
close all;
clear;
load imgfildata;
[file,path]=uigetfile({'*.jpg;*.bmp;*.png;*.tif'},'Choose an image');
s=[path,file];
picture=imread(s);
[~,cc]=size(picture);
picture=imresize(picture,[300 500]);
if size(picture,3)==3
picture=rgb2gray(picture);
end
%se=strel('rectangle',[5,5]);
%a=imerode(picture,se);
%figure,imshow(a);
%b=imdilate(a,se);
threshold = graythresh(picture);
picture =~im2bw(picture,threshold);
picture = bwareaopen(picture,30);
imshow(picture)
if cc>2000
picture1=bwareaopen(picture,3500);
else
picture1=bwareaopen(picture,3000);
end
figure,imshow(picture1)
picture2=picture-picture1;
figure,imshow(picture2)
picture2=bwareaopen(picture2,200);
figure,imshow(picture2)
[L,Ne]=bwlabel(picture2);
propied=regionprops(L,'BoundingBox');
hold on
pause(1)
for n=1:size(propied,1)
rectangle('Position',propied(n).BoundingBox,'EdgeColor','b','LineWidth',2)
end
hold off
figure
final_output=[];
t=[];
for n=1:Ne
[r,c] = find(L==n);
n1=picture(min(r):max(r),min(c):max(c));
n1=imresize(n1,[42,24]);
figure,imshow(n1)
imwrite(n1,'.bmp')
pause(0.1)
x=[ ];
totalLetters=size(imgfile,2);
for k=1:totalLetters
y=corr2(imgfile{1,k},n1);
x=[x y];
end
t=[t max(x)];
if max(x)>.45
z=find(x==max(x));
out=cell2mat(imgfile(2,z));
final_output=[final_output out];
end
end
p=final_output;
i=1;
j=1;
for n=1:length(p)
if (p(n)=='1')
p1(i)=p(n);
i=i+1;
continue;
end
if (p(n)=='2')
p1(i)=p(n);
i=i+1;
continue;
end
if (p(n)=='3')
p1(i)=p(n);
i=i+1;
continue;
end
if (p(n)=='4')
p1(i)=p(n);
i=i+1;
continue;
end
if (p(n)=='5')
p1(i)=p(n);
i=i+1;
continue;
end
if (p(n)=='6')
p1(i)=p(n);
i=i+1;
continue;
end
if (p(n)=='7')
p1(i)=p(n);
i=i+1;
continue;
end
if (p(n)=='8')
p1(i)=p(n);
i=i+1;
continue;
end
if (p(n)=='9')
p1(i)=p(n);
i=i+1;
continue;
end
if (p(n)=='0')
p1(i)=p(n);
i=i+1;
continue;
end
p2(j)=p(n);
j=j+1;
end
file = fopen('number_Plate.txt', 'wt');
fprintf(file, "Dhaka Metro ") ;
fprintf(file,'%s\n',p2);
fprintf(file,'%s\n',p1);
fclose(file);
winopen('number_Plate.txt')