Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 车牌上的所有字符都无法识别_Matlab_Image Processing - Fatal编程技术网

Matlab 车牌上的所有字符都无法识别

Matlab 车牌上的所有字符都无法识别,matlab,image-processing,Matlab,Image Processing,我正在从车牌中提取和分割字符。我面临着字符识别的问题。我想提取数字和符号,不要考虑字母表。我从八中得到一个字符作为输出。运行此代码后,我得到的答案是“1”。我附加matlab代码的位置和板块分割。我已经给出了输入图像供参考。`][[]有人能帮我纠正这个错误吗 function [ImgPlate] = LocationPlate(I) %% Cutting and resizing the original image %% % I=imread('2222.jpg'); % figure,i

我正在从车牌中提取和分割字符。我面临着字符识别的问题。我想提取数字和符号,不要考虑字母表。我从八中得到一个字符作为输出。运行此代码后,我得到的答案是“1”。我附加matlab代码的位置和板块分割。我已经给出了输入图像供参考。`][[]有人能帮我纠正这个错误吗

function [ImgPlate] = LocationPlate(I)

%% Cutting and resizing the original image %%
% I=imread('2222.jpg');
% figure,imshow(I);

[rows columns]=size(I);
columns=columns/3;
xmin=round(0.20*rows);
ymin=round(0.20*columns);
width=round((0.85*columns)-(0.10*columns));
height=round((0.85*rows)-(0.15*rows));
Io=imcrop(I,[xmin ymin width height]);
Io=imresize(Io,[480 640]);
Io=rgb2gray(Io);
Io=imadjust(Io);

 %% Image processing to focus the area of number plate %%
 %% Smooth edges and contours to delete characters.

 se=strel('rectangle',[6 30]);

    Ic=imclose(Io,se);
    Ic=imadjust(Ic);
    tophat=Ic-Io;
    Ibw=(tophat>85);

 %% Remove the related elements with fewer than 70 pixels %%
 %% Remove objects that are not plate %%

 plate= bwlabel(Ibw,4);
 obj= max(max(plate));
 dim1 = regionprops(plate, 'area')';

    dim=[dim1.Area];
    dim(find(dim<70))=0;

for i=1:obj


index=find(plate==i);
if dim(i)==0
    plate(index)=0;

else
    plate(index)=1;
end

end


CC=bwconncomp(plate);
P=regionprops(CC,'all');
[rp cp]=size(plate);


 for i=1:CC.NumObjects


    if P(i).MajorAxisLength>(2*cp/3)
    plate(P(i).PixelIdxList(:,1))=0;
    end

  end

 %% Remove objects that are not candidates for plate %%

 se3=strel('rectangle',[30 70]);
 r2=imclose(plate,se3);

 se2=strel('rectangle',[5 30]);
 r=imdilate(r2,se2);


    CC=bwconncomp(r);
    P=regionprops(CC,'all');

 for i=1:CC.NumObjects


    if P(i).MajorAxisLength>(2*cp/3)
    r(P(i).PixelIdxList(:,1))=0;

    end

    end

 %% select the largest connected component after preprocessing, the
    %%plate

 plate1= bwlabel(r,4);
 dim2= regionprops(plate1, 'area')';

    dim1=[dim2.Area];
    f=max(dim1);
    indMax=find(dim1==f);
    plate1(find(plate1~=indMax))=0;

 %% cutting of original image %%

 [cuty, cutx] = find( plate1 > 0);
 up = min(cuty);

    down = max(cuty);
    left = min(cutx);
    right = max(cutx);
    img_cut_v = Io(up:down,:,:);
    img_cut_h = img_cut_v(:,left:right,:);

    ImgPlate = img_cut_h;

    %% different mask for location plate %%


    [r c]=size(ImgPlate);


    if r<25 || r>65

    [rows columns]=size(I);
    columns=columns/3;
    xmin=round(0.20*rows);
    ymin=round(0.20*columns);
    width=round((0.85*columns)-(0.10*columns));
    height=round((0.85*rows)-(0.15*rows));
    Io=imcrop(I,[xmin ymin width height]);
    Io=imresize(Io,[480 640]);
    Io=rgb2gray(Io);
    Io=imadjust(Io);

    se=strel('rectangle',[6 30]);
    Ic=imclose(Io,se);
    Ic=imadjust(Ic);
    tophat=Ic-Io;
    Ibw1=(tophat>85);
    mask=zeros(480,640);
    for i=40:370
    for j=40:575
    mask(i,j)=1;
    end
    end


    Ibw=Ibw1 & im2bw(mask);
    plate= bwlabel(Ibw,4);
    obj= max(max(plate));
    dim1 = regionprops(plate, 'area')';
    dim=[dim1.Area];
    dim(find(dim<70))=0;


    for i=1:obj
    index=find(plate==i);
    if dim(i)==0
    plate(index)=0;

    else
    plate(index)=1;

    end
    end


    CC=bwconncomp(plate);
    P=regionprops(CC,'all');
    [rp cp]=size(plate);


    for i=1:CC.NumObjects
    if P(i).MajorAxisLength>(cp/3)
    plate(P(i).PixelIdxList(:,1))=0;

    end
    end


    se3=strel('rectangle',[30 70])



    r2=imclose(plate,se3);
    se2=strel('rectangle',[5 30]);
    r=imdilate(r2,se2);


    plate1= bwlabel(r,4);
    dim2= regionprops(plate1, 'area')';
    dim1=[dim2.Area];
    f=max(dim1);
    indMax=find(dim1==f);
    plate1(find(plate1~=indMax))=0;

    [cuty, cutx] = find( plate1 > 0);

    up = min(cuty);
    down = max(cuty);
    left = min(cutx);
    right = max(cutx);
    img_cut_v = Io(up:down,:,:);
    img_cut_h = img_cut_v(:,left:right,:);
    ImgPlate = img_cut_h;

    end

    %% Representation %%


    % figure(1);
    % imshow(I);
    % subplot(2,2,1);imshow(I);
    % subplot(2,2,2);imshow(Ic);% subplot(2,2,3);imshow(plate);
    % subplot(2,2,4);imshow(plate1);


    figure(2);  imshow(img_cut_h);title('output location plate');
    end
function [Objects,ImgChar]=Segmentation(ImgPlate)

    %% Binarize the image %%
    level = graythresh(ImgPlate);
    Ibw =(im2bw(ImgPlate,level));


    %% Select the orientation of the largest object in the image.
    %% Turn this angle at the picture.
    %% Plate cutting to segment the characters that compose %%


    Fl=bwlabel(Ibw);
    Statsbf=regionprops(Fl,'all');
    Flmax=find([Statsbf.Area]==max([Statsbf.Area]));
    angle=Statsbf(Flmax).Orientation;
    F2=imrotate(Fl,-angle);
    L=bwlabel(F2);
    Statsbf=regionprops(L,'all');
    maxi=find([Statsbf.Area]==max([Statsbf.Area]));
    BB=Statsbf(maxi).BoundingBox;
    F2=imcrop(F2,[BB(1,1) BB(1,2) BB(1,3) BB(1,4)]);
% figure,imshow(F2);

    %% First three and last three rows to zero.
    %% First two and last two columns to zero.
    %% So remove connectivity between characters and background %%
    %% Remove small impurities %%


    L4=not(F2);
    [r c]=size(L4);
    L4(1,:)=0;
    L4(2,:)=0;
    L4(3,:)=0;
    L4(r,:)=0;
    L4(r-1,:)=0;
    L4(r-2,:)=0;
    L4(:,1)=0;
    L4(:,2)=0;
    L4(:,c)=0;
    L4(:,c-1)=0;


    L4b=bwlabel(L4);
    Stats3=regionprops(L4b,'all');
    sarea3=[Stats3.Area];
    G=find(sarea3<70);


    for cv=1:length(G)
    G1=find(L4b==G(cv));
    L4(G1)=0;

    end
    [r c]=size(L4);
    CC=bwconncomp(L4);
    L=bwlabel(L4);
    ind2=max(L(:,c-2));
    P=regionprops(CC,'all');

    %% Remove objects smaller and larger than a character %%


    i=1;
    if  (max(P(i,1).PixelList(:,1))-min(P(i,1).PixelList(:,1)))<(c/13)
             L4(CC.PixelIdxList{1,i})=0;
    end

    for i=1:CC.NumObjects


    if (max(P(i,1).PixelList(:,1))-min(P(i,1).PixelList(:,1)))>(2*c/3)
         L4(CC.PixelIdxList{1,i})=0;

    end

    if (max(P(i,1).PixelList(:,2))-min(P(i,1).PixelList(:,2)))<(r/3)

       L4(CC.PixelIdxList{1,i})=0;
    end


    if (max(P(i,1).PixelList(:,1))-min(P(i,1).PixelList(:,1)))<(c/8)
        L4(find(L==ind2))=0;

    end

    end


    L4=imclose(L4,strel('disk',1));
    L4=imopen(L4,strel('disk',1));
%   figure(4);
    imshow(L4);
    L4b=bwlabel(L4);
    Stats3b=regionprops(L4b,'all');

    N=length(Stats3b);


    while N>8
    L4=imdilate(L4,strel('disk',1));
    L4b=bwlabel(L4);
    Stats3b=regionprops(L4b,'all');
    N=length(Stats3b);

    end


    L4b=bwlabel(L4);
    Stats3b=regionprops(L4b,'all');
    ImgChar=zeros(100,100,N);

 %% Dividing characters which are connected %%
 %% Remove objects that have been listed as characters but are not%
 %% Show every character in the correct position %%


    cont=0;
    cont1=0;

 for i=1:N

    [r1 c1]=size(Stats3b(i,1).Image);


    if c1>round(c/6)
    cont1=cont;
    Stats3b(i,1).Image(:,round(c1/2))=0;
    L5=Stats3b(i,1).Image;
    CC=bwconncomp(L5);
    CC1=regionprops(CC,'all');

    for j=1:CC.NumObjects
    [r2 c2]=size(CC1(j,1).Image);
    if c2>round(c/7)

    CC1(j,1).Image(:,round(c2/2))=0;
    L6=CC1(j,1).Image;
    LL=bwconncomp(L6);
    CC2=regionprops(LL,'all');
    for k=1:LL.NumObjects

    CC2(k).Image=imresize(CC2(k).Image, [100 100]);
    figure;imshow((CC2(k).Image))
    ImgChar(:,:,i+cont1)=not(CC2(k).Image);
    cont1=cont1+1;
    end
    cont=cont+1;
    else

    CC1(j).Image=imresize(CC1(j).Image, [100 100]);

    figure;imshow((CC1(j).Image))
    ImgChar(:,:,i+cont1)=not(CC1(j).Image);
    cont1=cont1+1;
    end
    end

    cont=cont+1;


    else
    Stats3b(i).Image=imresize(Stats3b(i).Image, [100 100]);
    figure;imshow((Stats3b(i).Image));


    if cont~=0
    ImgChar(:,:,i+cont)=not(Stats3b(i).Image);
    else
    ImgChar(:,:,i)=not(Stats3b(i).Image);

    end
end
end

 %% Remove spurious %%

 [x, y, Objects]=size(ImgChar);
end

function [strPlate] = Recognition(I)
    I=imread('2222.jpg');
    [ImgPlate] = LocationPlate(I);
    [Objects,ImgChar]=Segmentation(ImgPlate);
    N=struct('Image',{});
    numbers={'0','1','2','3','4','5','sign'};
    N(1).Image=imresize(im2bw(uint8(imread('untitled0.bmp'))),[100 100]);
    N(2).Image=imresize(im2bw(uint8(imread('untitled1.bmp'))),[100 100]);
    N(3).Image=imresize(im2bw(uint8(imread('untitled2.bmp'))),[100 100]);
    N(4).Image=imresize(im2bw(uint8(imread('untitled3.bmp'))),[100 100]);
    N(5).Image=imresize(im2bw(uint8(imread('untitled4.bmp'))),[100 100]);
    N(6).Image=imresize(im2bw(uint8(imread('untitled5.bmp'))),[100 100]);
    N(7).Image=imresize(im2bw(uint8(imread('sign.jpg'))),[100 100]);
    if Objects==8
       strPlate=[];
         for i=1:Objects
         char=ImgChar(:,:,i);
            if  (i==2)||(i==3)||(i==4) || (i==5) || (i==6)||(i==7) ||(i==8)
                list_corr=[];
                for j=1:7
                    corr=corr2(N(j).Image,char);
                   list_corr=[list_corr corr];
               end
            f=max(list_corr);
            maxcorr=find(list_corr==f);
            strPlate=[strPlate numbers(maxcorr)];
         end
      end
    end
 end
函数[ImgPlate]=定位板(I)
%%剪切原始图像并调整其大小%%
%I=imread('2222.jpg');
%图,imshow(I);
[行-列]=大小(I);
列=列/3;
xmin=圆形(0.20*行);
ymin=圆形(0.20*列);
宽度=圆形((0.85*列)-(0.10*列));
高度=圆形((0.85*行)-(0.15*行));
Io=imcrop(I,[xmin-ymin宽-高]);
Io=imresize(Io[480 640]);
Io=RGB2灰色(Io);
Io=imadjust(Io);
%%图像处理以聚焦车牌区域%%
%%平滑边缘和轮廓以删除字符。
se=strel(‘矩形’,[6 30]);
Ic=imclose(Io,se);
Ic=imadjust(Ic);
tophat=Ic-Io;
Ibw=(tophat>85);
%%删除小于70像素的相关元素%%
%%移除非板材%%的对象
板=BW标签(Ibw,4);
obj=最大值(最大值(板));
dim1=区域支柱(板,“区域”);
dim=[dim1.面积];
尺寸(查找)(尺寸(2*cp/3)
平板(P(i).PixelIdxList(:,1))=0;
结束
结束
%%移除不是板%%候选对象的对象
se3=strel(‘矩形’,[30 70]);
r2=imclose(板,se3);
se2=strel(‘矩形’,[5 30]);
r=扩张(r2,se2);
CC=BWConComp(r);
P=区域属性(CC,'all');
对于i=1:CC.numbjects
如果P(i).MajorAxisLength>(2*cp/3)
r(P(i).PixelIdxList(:,1))=0;
结束
结束
%%选择预处理后连接的最大零部件,即
%%盘子
板1=BWR标签(r,4);
dim2=区域支柱(平台1,'区域');
dim1=[dim2.面积];
f=最大值(dim1);
indMax=find(dim1==f);
plate1(find(plate1~=indMax))=0;
%%原始图像的剪切%%
[cuty,cutx]=查找(plate1>0);
向上=最小值(cuty);
向下=最大值(cuty);
左=最小值(cutx);
右=最大值(cutx);
img_cut_v=Io(向上:向下,:,:);
img_cut_h=img_cut_v(:,左:右,:);
ImgPlate=img\u cut\u h;
%%定位板的不同遮罩%%
[r c]=尺寸(ImgPlate);
如果r65
[行-列]=大小(I);
列=列/3;
xmin=圆形(0.20*行);
ymin=圆形(0.20*列);
宽度=圆形((0.85*列)-(0.10*列));
高度=圆形((0.85*行)-(0.15*行));
Io=imcrop(I,[xmin-ymin宽-高]);
Io=imresize(Io[480 640]);
Io=RGB2灰色(Io);
Io=imadjust(Io);
se=strel(‘矩形’,[6 30]);
Ic=imclose(Io,se);
Ic=imadjust(Ic);
tophat=Ic-Io;
Ibw1=(tophat>85);
掩码=零(480640);
对于i=40:370
对于j=40:575
掩模(i,j)=1;
结束
结束
Ibw=Ibw1和im2bw(遮罩);
板=BW标签(Ibw,4);
obj=最大值(最大值(板));
dim1=区域支柱(板,“区域”);
dim=[dim1.面积];
仪表盘集成模块(查找)(仪表盘集成模块(cp/3)
平板(P(i).PixelIdxList(:,1))=0;
结束
结束
se3=strel(‘矩形’,[30 70])
r2=imclose(板,se3);
se2=strel(‘矩形’,[5 30]);
r=扩张(r2,se2);
板1=BWR标签(r,4);
dim2=区域支柱(平台1,'区域');
dim1=[dim2.面积];
f=最大值(dim1);
indMax=find(dim1==f);
plate1(find(plate1~=indMax))=0;
[cuty,cutx]=查找(plate1>0);
向上=最小值(cuty);
向下=最大值(cuty);
左=最小值(cutx);
右=最大值(cutx);
img_cut_v=Io(向上:向下,:,:);
img_cut_h=img_cut_v(:,左:右,:);
ImgPlate=img\u cut\u h;
结束
%%代表%%
%图(1);
%imshow(I);
%子地块(2,2,1);imshow(I);
%子批次(2,2,2);imshow(Ic);%子批次(2,2,3);imshow(板材);
%子地块(2,2,4);imshow(平台1);
图(2);图像显示(图像分割);标题(“输出位置板”);
结束
函数[对象,ImgChar]=分段(ImgPlate)
%%对图像进行二值化%%
级别=灰度阈值(ImgPlate);
Ibw=(im2bw(ImgPlate,级别));
%%选择图像中最大对象的方向。
%%在图片上转动这个角度。
%%用于分割构成%%
Fl=bwlabel(Ibw);
Statsbf=区域道具(Fl,'all');
Flmax=find([Statsbf.Area]==max([Statsbf.Area]);
角度=状态BF(Flmax)。方向;
F2=旋转(Fl,-角度);
L=bwlabel(F2);
Statsbf=区域道具(L,“全部”);
maxi=find([Statsbf.Area]==max([Statsbf.Area]);
BB=Statsbf(最大值)。边界框;
F2=imcrop(F2,[BB(1,1)BB(1,2)BB(1,3)BB(1,4)]);
%图,imshow(F2);
%%前三行和后三行为零。
%%前两列和后两列的值为零。
%%因此,请删除字符和背景之间的连接%%
%%去除少量杂质%%
L4=非(F2);
[RC]=尺寸(L4);
L4(1,:)=0;
L4(2,:)=0;
L4(3,:)=0;
L4(r,:)=0;
L4(r-1,:)=0;
L4(r-2,:)=0;
L4(:,1)=0;
L4(:,2)=0;
L4(:,c)=0;
L4(:,c-1)=0;
L4b=bwlabel(L4);
Stats3=区域支柱(L4b,“全部”);
sarea3=[Stats3.面积];
G=查找(Sarea3轮(c/7)
CC1(j,1)。图像(:,圆形(c2/2))=0;
L6=CC1(j,1)。图像;
LL=BWConComp(L6);
CC2=区域道具(LL,'all');
对于k=1:LL.numbjects
CC2(k).Image=imresize(CC2(k).Image[100]);
图;imshow((CC2(k).图像))
ImgChar(:,:,i+cont1)=非(CC2(k).Image);
cont1=cont1+1;
结束
cont=cont+1;
其他的
CC1(j).Image=imresize(CC1(j).Image[100]);
图;imshow((CC1(j.图像))
ImgChar(:,:,i+cont1)=非(CC1(j).Image);
cont1=cont1+1;
结束
结束
cont=cont+1;
其他的
Stats3b(i).Image=imresize(Stats3b(i).Image[100]);
图;imshow((Stats3b(i).Image));
如果cont~=0
ImgChar(:,:,i+cont)=非(Stats3b(i).Image);
其他的
ImgChar(:,:,i)=not(Stats3b(i).Image);
结束
结束
结束
%%去除虚假%%
[x,y,Objects]=大小(ImgChar);
结束
函数[strPlate]=识别(I)
I=imread('2222.jpg');
[ImgPlate]=定位板(I);
[对象,ImgChar]=分段
 for i=1:Objects
        char=ImgChar(:,:,i);
        if  (i==2)||(i==3)||(i==4) || (i==5) || (i==6)||(i==7) ||(i==8)
            list_corr=[];
            for j=1:6
                corr=corr2(N(j).Image,char);
                list_corr=[list_corr corr];
            end
            close all
            figure;imshow(char)
            f=max(list_corr);
            maxcorr=find(list_corr==f);
            strPlate=[strPlate numbers(maxcorr)];
        end
    end
Stats3b(i).Image=imresize(Stats3b(i).Image, [100 100]);
        figure;
        imshow((Stats3b(i).Image));

        ImgChar(:,:,i) = Stats3b(i).Image;% added

        if cont~=0

        else
            ImgChar(:,:,i)=not(Stats3b(i).Image);

        end