Guest User

Untitled

a guest
Jan 17th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. desiredsize = [42 24];
  2. files = {'1', '2', '3', '4', '5', '0', 'sign'};
  3. NewTemplates1 = cell(size(files));
  4. for fileidx = 1:numel(files)
  5. img = imread([files{fileidx}, '.png']);
  6. img= rgb2gray(img);
  7. img = imresize(img, desiredsize);
  8. NewTemplates1{fileidx} = img;
  9. end
  10.  
  11. clc;
  12. clear all;
  13. load NewTemplates1;
  14. word=[ ];
  15. img=imread('2222.jpg');
  16. figure,imshow(img);
  17. [~,cc]=size(img);
  18. picture=imresize(img,[300 500]);
  19.  
  20. if size(picture,3)==3
  21. picture=rgb2gray(picture); %grey values are btwn 0 to 1 or 0 to 255
  22. end
  23.  
  24.  
  25.  
  26. threshold = graythresh(picture); %greythresh gives the threshold value of greyscale image
  27. 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
  28. picture = bwareaopen(picture,30); % those things that have less than 30 pixels are removed
  29.  
  30.  
  31. if cc>2000
  32. picture1=bwareaopen(picture,3500); %those things that have less than 3500 pixels are removed ie excluding nmbr plate
  33. else
  34. picture1=bwareaopen(picture,3000); %those things that have less than 3000 pixels are removed ie excluding nmbr plate
  35. end
  36. figure,imshow(picture1);
  37. picture2=picture-picture1; %only number plate is left
  38. picture2=bwareaopen(picture2,50); %only text is there in the nmbr plate
  39. figure,imshow(picture2);
  40. title('plate extracted');
  41. [L,Ne]=bwlabel(picture2,8);
  42. %% Measure properties of image regions
  43. propied=regionprops(L,'BoundingBox');
  44. hold on
  45. %% Plot Bounding Box
  46. for n=1:size(propied,1)
  47. rectangle('Position',propied(n).BoundingBox,'EdgeColor','g','LineWidth',2)
  48. end
  49. hold off
  50. pause (1)
  51. % Compute the number of letters in template file
  52. num_letras=size(NewTemplates1,2);
  53. %% Objects extraction
  54. figure
  55. for n=1:Ne
  56. [r,c] = find(L==n);
  57. n1=picture2(min(r):max(r),min(c):max(c));
  58. img_r=imresize(n1,[42 24]);
  59. letter=readLetter1(img_r);
  60. % Letter concatenation
  61. word=[word letter];
  62. fid = fopen('noPlate.txt', 'wt'); % This portion of code writes the number plate
  63. fprintf(fid,'%sn',word); % to the text file, if executed a notepad file with the
  64. fclose(fid); % name noPlate.txt will be open with the number plate written.
  65. winopen('noPlate.txt')
  66.  
  67. % imshow(~n1);
  68. pause(0.5);
  69. end
Add Comment
Please, Sign In to add comment