• 车牌识别之识别与分割


    1.定位,主要就是根据颜色特征,中国的车牌大都是蓝牌的,也就用这种最典型的了

    2.分割,分割首先还是建立在第一步基础上,然后是用位置和投影来进行分割

    哇,注释全乱了。。。。。。。

    clear all;
    pic=imread('1.jpg');
    figure;subplot(1,4,1);imshow(pic);title('original image')
    % subplot ??????m*n?????????p???,p=1?????????
    [ysize,xsize,zsize]=size(pic);%????????????????????????
    %ysize?xsize???????zsize????????
    pic_r=double(pic(:,:,1));%?????????
    pic_g=double(pic(:,:,2));
    pic_b=double(pic(:,:,3));
    for(i=1:ysize)
        for (j=1:xsize)
          mean(i,j)=(pic_r(i,j)+pic_g(i,j)+pic_b(i,j))/3;%???????
          blue(i,j)=pic_b(i,j)-mean(i,j);
          if(blue(i,j)>30)
               blue0(i,j)= 1;
           else
               blue0(i,j)=0;
          end
        end
    end
    subplot(1,4,2);imshow(blue0);title('blue0')
    h=[1 1 1 1];
    blue1=filter2(h,blue0);%??????????????h???????????
    for(i=1:ysize)
        for(j=1:xsize)
           if blue1(i,j)>=1
              blue1(i,j)=1;
           else
               blue1(i,j)=0;
           end
        end
    end
    blue2=bwareaopen(blue1,1000);
    %BW2 = bwareaopen(BW,P,conn) ??????BW?????P?????????conn??8??
    subplot(1,4,3);imshow(blue1);title('blue1')
    subplot(1,4,4);imshow(blue2);title('blue2')
    xsize1=uint16(0.1*xsize);
    xsize2=uint16(0.9*xsize);%xsize?????
    ysize1=uint16(0.4*ysize);%ysize??????
    ysize2=uint16(ysize);
    x=zeros(1,xsize);%????1???xsize??0??
    y=zeros(1,ysize);
    for(i=ysize1:ysize2)
        for(j=xsize1:xsize2)
            if blue2(i,j)>0
               x(j)=x(j)+1;
               y(i)=y(i)+1;
            end
        end
    end
    figure;subplot(2,2,1);plot(x);title('x');
           subplot(2,2,2);plot(y) ;title('y');
    for(i=1:ysize)
          if y(i)>=1
              yy(i)=1;%??????????????
          else
               yy(i)=0;
          end    
    end
    for(j=1:xsize)
          if x(j)>=1
              xx(j)=1;
          else
             xx(j)=0;
          end    
    end
    subplot(2,2,3);plot(xx);title('xx');
    subplot(2,2,4);plot(yy) ;title('yy');
    for(i=1:ysize-1)
         if(yy(i)==1&yy(i+1)==0)
            y2=i;
         end     
     end
    for(i=ysize-1:-1:1)
         if(yy(i)==0&yy(i+1)==1)
            y1=i;
         end     
    end
    h=y2-y1;
    for(j=1:xsize-1);
        if(xx(j)==1&xx(j+1)==0)
           x2=j;
        end
    end
    for(j=xsize-1:-1:1);
        if (xx(j)==0&xx(j+1)==1)
            x1=j;
        end
    end
    w=x2-x1;
    for (m=1:h)
        for(n=1:w)
        lp_rgb(m,n,:)=pic(m+y1,n+x1,:);
        end
    end
    figure;subplot(2,3,1);imshow(lp_rgb);
    lp_resize = imresize(lp_rgb,[34,113],'nearest');
    lp_gray=rgb2gray(lp_resize); 
    subplot(2,3,2);imshow(lp_gray);
    mean=mean2(lp_gray);
    for(i=1:34)
        for(j=1:113)
            if lp_gray(i,j)>=mean;
                lp_b1(i,j)=1;
            else
                lp_b1(i,j)=0;
            end
        end
    end
    subplot(2,3,3);imshow(lp_b1);
    lp_b2=bwareaopen(lp_b1,6);
    subplot(2,3,4);imshow(lp_b2);
    lp_b=bwmorph(lp_b2,'thin');
    subplot(2,3,5);imshow(lp_b);
    for(m=1:26)
        for(n=1:113)
           if(n>1&n<=16);
             cha1(m,n-1)=lp_b(m+4,n); 
           elseif(n>16&n<=31);
             cha2(m,n-16)=lp_b(m+4,n);
           elseif(n>37&n<=52);
             cha3(m,n-37)=lp_b(m+4,n);
           elseif(n>52&n<=67);
             cha4(m,n-52)=lp_b(m+4,n);
           elseif(n>67&n<=82);
             cha5(m,n-67)=lp_b(m+4,n);
           elseif(n>82&n<=97);
             cha6(m,n-82)=lp_b(m+4,n);
           elseif(n>97&n<=112);
             cha7(m,n-97)=lp_b(m+4,n);
           end
       end
    end
    figure;subplot(1,7,1);imshow(cha1);  
    subplot(1,7,2);imshow(cha2);  
    subplot(1,7,3);imshow(cha3);  
    subplot(1,7,4);imshow(cha4);  
    subplot(1,7,5);imshow(cha5);  
    subplot(1,7,6);imshow(cha6);  
    subplot(1,7,7);imshow(cha7);  
    

     这个是只做了定位的功能,没有做分割的功能

    function lpr_loc()
    % license plate recognition - car plate location based on color model
    
    I=imread('Car.jpg');
    [y,x,z]=size(I);
    myI=double(I);
    %%%%%%%%%%% RGB to HSI  %%%%%%%%
    tic   % ����������������������������
    
    %%%%%%%%%%% �������� %%%%%%%%%%%%%%%
    %%%%%%%% Y ���� %%%%%%%%%%
    Blue_y=zeros(y,1);
    for i=1:y
        for j=1:x
                if((myI(i,j,1)<=121)&&myI(i,j,1)>=110&&((myI(i,j,2)<=155)&&(myI(i,j,2)>=141))&&((myI(i,j,3)<=240)&&(myI(i,j,3)>=210))) 
    % ����RGB����������
                   Blue_y(i,1)= Blue_y(i,1)+1;     % ��������������          
               end  
        end       
    end
    [temp MaxY]=max(Blue_y);        % Y����������������
    PY1=MaxY;
    while ((Blue_y(PY1,1)>=5)&&(PY1>1))
           PY1=PY1-1;
    end    
    PY2=MaxY;
    while ((Blue_y(PY2,1)>=5)&&(PY2<y))
           PY2=PY2+1;
    end
    IY=I(PY1:PY2,:,:);
    
    %%%%%%%% X ���� %%%%%%%%%% 
    Blue_x=zeros(1,x);             
    for j=1:x
        for i=PY1:PY2
                if((myI(i,j,1)<=121)&&myI(i,j,1)>=110&&((myI(i,j,2)<=155)&&(myI(i,j,2)>=141))&&((myI(i,j,3)<=240)&&(myI(i,j,3)>=210))) 
                   Blue_x(1,j)= Blue_x(1,j)+1;               
               end  
        end       
    end
    
    PX1=1;
    while ((Blue_x(1,PX1)<3)&&(PX1<x))
           PX1=PX1+1;
    end    
    PX2=x;
    while ((Blue_x(1,PX2)<3)&&(PX2>PX1))
           PX2=PX2-1;
    end
    PX1=PX1-2; % ����������������
    PX2=PX2+2;
    
    Plate=I(PY1:PY2,PX1-2:PX2,:);
    t=toc % ��������
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    figure,imshow(I);
    figure,plot(Blue_y);grid
    figure,plot(Blue_x);grid
    figure,imshow(IY);
    figure,imshow(Plate);
    

      

  • 相关阅读:
    Spring IoC容器的设计——BeanFactory应用场景2
    Spring IoC容器的设计——BeanFactory应用场景
    jQuery学习备忘
    Spring IoC容器的设计—3—次线
    Spring IoC容器的设计—2—主线
    Spring IoC容器的设计—1—主线
    关于备忘信息重置解决方案
    E45: 'readonly' option is set (add ! to override)
    未知高度元素居中
    background
  • 原文地址:https://www.cnblogs.com/guohaoyu110/p/7613337.html
Copyright © 2020-2023  润新知