Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- clc;
- clear all;
- load NewTemplates1;
- word=[ ];
- img=imread('2222.jpg');
- figure,imshow(img);
- [~,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
- figure,imshow(picture1);
- 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,8);
- %% Measure properties of image regions
- propied=regionprops(L,'BoundingBox');
- hold on
- %% Plot Bounding Box
- for n=1:size(propied,1)
- rectangle('Position',propied(n).BoundingBox,'EdgeColor','g','LineWidth',2)
- end
- hold off
- pause (1)
- % Compute the number of letters in template file
- num_letras=size(NewTemplates1,2);
- %% Objects extraction
- figure
- for n=1:Ne
- [r,c] = find(L==n);
- n1=picture2(min(r):max(r),min(c):max(c));
- img_r=imresize(n1,[42 24]);
- letter=readLetter1(img_r);
- % Letter concatenation
- word=[word letter];
- fid = fopen('noPlate.txt', 'wt'); % This portion of code writes the number plate
- fprintf(fid,'%sn',word); % to the text file, if executed a notepad file with the
- fclose(fid); % name noPlate.txt will be open with the number plate written.
- winopen('noPlate.txt')
- % imshow(~n1);
- pause(0.5);
- end
Add Comment
Please, Sign In to add comment