车辆牌照字符识别——matlab

车辆牌照字符识别——matlab

标签: matlab
1259人阅读 评论(0) 收藏 举报
本文章已收录于:
分类:

车辆牌照字符识别方法:采用人工神经网络法

I0=pretreatment(imread('0.bmp')); 
I1=pretreatment(imread('1.bmp')); 
I2=pretreatment(imread('2.bmp')); 
I3=pretreatment(imread('3.bmp')); 
I4=pretreatment(imread('4.bmp')); 
I5=pretreatment(imread('5.bmp')); 
I6=pretreatment(imread('6.bmp')); 
I7=pretreatment(imread('7.bmp')); 
I8=pretreatment(imread('8.bmp')); 
I9=pretreatment(imread('9.bmp')); 
I10=pretreatment(imread('A.bmp')); 
I11=pretreatment(imread('B.bmp')); 
I12=pretreatment(imread('C.bmp')); 
I13=pretreatment(imread('D.bmp')); 
I14=pretreatment(imread('E.bmp')); 
I15=pretreatment(imread('F.bmp')); 
I16=pretreatment(imread('G.bmp')); 
I17=pretreatment(imread('H.bmp')); 
I18=pretreatment(imread('J.bmp')); 
I19=pretreatment(imread('K.bmp')); 
I20=pretreatment(imread('L.bmp')); 
I21=pretreatment(imread('M.bmp')); 
I22=pretreatment(imread('N.bmp')); 
I23=pretreatment(imread('P.bmp'));
I24=pretreatment(imread('Q.bmp')); 
I25=pretreatment(imread('R.bmp')); 
I26=pretreatment(imread('S.bmp')); 
I27=pretreatment(imread('T.bmp')); 
I28=pretreatment(imread('U.bmp')); 
I29=pretreatment(imread('V.bmp')); 
I30=pretreatment(imread('W.bmp')); 
I31=pretreatment(imread('X.bmp')); 
I32=pretreatment(imread('Y.bmp')); 
I33=pretreatment(imread('Z.bmp')); 

P=[I0',I1',I2',I3',I4',I5',I6',I7',I8',I9',I10',I11',I12',I13',I14',I15',I16',I17',I18',I19',I20',I21',I22',I23',I24',I25',I26',I27',I28',I29',I30',I31',I32',I33'];
T=eye(34,34);
net=newff(minmax(P),[2000,300,34],{'logsig','logsig','logsig'},'trainrp');%minmax()求矩阵每一行向量的最大值和最小值
%函数newff建立一个可训练的前馈网络。这需要4个输入参数。
%第一个参数是一个Rx2的矩阵以定义R个输入向量的最小值和最大值; 
%第二个参数是一个设定每层神经元个数的数组; 
%第三个参数是包含每层用到的传递函数名称的细胞数组;
%最后一个参数是用到的训练函数的名称。
net.inputWeights{1,1}.initFcn='randnr';
net.inputWeights{2,1}.initFcn='randnr';
net.trainparam.epochs=8000;
net.trainparam.show=50;
net.trainparam.goal=0.0000000001;
net=init(net);%初始化权重和偏置的工作用命令init来实现。这个函数接收网络对象并初始化权重和偏置后返回网络对象。
[net,tr]=train(net,P,T);

i=imread('chepai.jpg');
dw=location(i);%车牌定位,见上上篇文章
[PIN0,PIN1,PIN2,PIN3,PIN4,PIN5,PIN6]=stringsplit(dw);%字符分割,见上篇文章
PIN0=pretreatment(PIN0);
PIN1=pretreatment(PIN1);
PIN2=pretreatment(PIN2);
PIN3=pretreatment(PIN3);
PIN4=pretreatment(PIN4);
PIN5=pretreatment(PIN5);
PIN6=pretreatment(PIN6);

P0=[PIN0',PIN1',PIN2',PIN3',PIN4',PIN5',PIN6'];
for i=2:7
    T0=sim(net,P0(:,i));%T0为P0(:,i)输入神经网络得到的输出,T0为34x1的列向量
    T1=compet(T0);% compet是神经网络的竞争传递函数,用于指出矩阵中每列的最大值。对应最大值的行的值为1,其他行的值都为0
    d=find(T1==1)-1;
    if(d==10)
        str='A';
    elseif(d==11)
        str='B';
    elseif(d==12)
        str='C';
    elseif(d==13)
        str='D';
    elseif(d==14)
        str='E';
    elseif(d==15)
        str='F';
    elseif(d==16)
        str='G';
    elseif(d==17)
        str='H';
    elseif(d==18)
        str='J';
    elseif(d==19)
        str='K';
    elseif(d==20)
        str='L';
    elseif(d==21)
        str='M';
    elseif(d==22)
        str='N';
    elseif(d==23)
        str='P';
    elseif(d==24)
        str='Q';
    elseif(d==25)
        str='R';
    elseif(d==26)
        str='S';
    elseif(d==27)
        str='T';
    elseif(d==28)
        str='U';
    elseif(d==29)
        str='V';
    elseif(d==30)
        str='W';
    elseif(d==31)
        str='X';
    elseif(d==32)
        str='Y';
    elseif(d==33)
        str='Z'; 
    else
        str=num2str(d);
    end
    switch i
        case 2
            str1=str;
        case 3
            str2=str;
        case 4
            str3=str;
        case 5
            str4=str;
        case 6
            str5=str;
        otherwise
            str6=str;
    end
end
s=strcat('',str1,str2,str3,str4,str5,str6);
figure();
imshow(dw),title(s);
    
    
  • 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
  • 135
  • 136
  • 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
  • 135
  • 136
function inp=pretreatment(I)
%此函数是将字符图片均转换成一维向量
if isrgb(I)
    I1=rgb2gray(I);
else
    I1=I;
end
I1=imresize(I1,[20,10]);%归一化
I1=im2bw(I1,0.9);
[m,n]=size(I1);
inp=zeros(1,m*n);
for j=1:n
    for i=1:m
        inp(1,m*(j-1)+i)=I1(i,j);
    end
end
    
    
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
0
0
 
 
function result = letter_compare(ocr_letters, document_letter) % LETTER_COMPARE.M % % function result = letter_compare(ocr_letters, document_letter) % % Parameters: ocr_letters is an array (1..4) of structures % with fields: Mean, Covariance % Subscripts of array mean 1=O 2=E 3=A 4=U % document_letter fields is a structure which has % with fields: Image, EulerNumber, Area, BoundingBox % % This function compares a letter extracted from the image paragraph % to each of the four vowels. Returns the index of the vowel % which the letter from the paragraph matches, if any. % If no vowels match up, return 0. % % Assumptions: % - the letter form the document/paragraph is properly oriented % Calculate the data necessary for the matching perImg = bwperim(document_letter.Image); perArea = bwarea(perImg); compactness = perArea^2/document_letter.Area; moments = invmoments(document_letter.Image); % Calculate the top/bottom area ratio midpoint = floor(document_letter.BoundingBox(4)/2); topPart = document_letter.Image(1:midpoint,:); bottomPart = document_letter.Image((midpoint+1):end,:); partRatio = bwarea(topPart)/bwarea(bottomPart); % Final vector for the doucment image which will be used for comparison vector = [ moments(1) moments(2) moments(3) compactness partRatio ]; % Go through all four letters for i = 1: 4, % Closeness will be Mahalanobis distance without the log term closeness(i) = (vector - ocr_letters(i).Mean)*... inv(ocr_letters(i).Covariance)*... (vector - ocr_letters(i).Mean)'; % Distance is Mahalanobis distance with the log term % The log term equalizes the distance space so that % we can compare which one of the four letters % is closer to the letter extracted from the paragraph distance(i) = closeness(i) + log(det(ocr_letters(i).Covariance)); end % Find one of the vowels with the smallest distance to the document letter minimumDistance = distance(1); closestMatch = 1; for j = 1:4, if distance(j)<minimumDistance minimumDistance = distance(j); closestMatch = j; end end % Now we have to determine if the closest match is noise or not variance = [ ocr_letters(closestMatch).Covariance(1,1) ... ocr_letters(closestMatch).Covariance(2,2) ... ocr_letters(closestMatch).Covariance(3,3) ... ocr_letters(closestMatch).Covariance(4,4) ... ocr_letters(closestMatch).Covariance(5,5) ]; % Standard deviation std = sqrt(variance); matchCloseness = closeness(closestMatch); % Use Mahalanobis distance to figure out the allowed range for % the closeness within which the letter is accepted as a match allowedRange = 6.5*(std) * inv(ocr_letters(closestMatch).Covariance) * (std)'; % Closeness is within allowed interval if (matchCloseness <= allowedRange) % ###################### SECONDARY CHECKS ################ if closestMatch == 1 % It thinks it is an O if (document_letter.EulerNumber ~= 0) % Reject closestMatch = 0; end elseif closestMatch == 2 % It thinks it is an E if (document_letter.EulerNumber ~= 0) % Reject closestMatch = 0; end elseif closestMatch == 3 % It thinks it is an A % Euler# can be 0 or 1 if (document_letter.EulerNumber ~= 0) & ... (document_letter.EulerNumber ~= -1) % Reject closestMatch = 0; end % Ahh, but it might be an S ! % S's have about equal distribution % of weight about their midpoint if (partRatio > 0.87 ) % S rejected because the weight of the top % half is about equal to the wight of the % bottom half closestMatch = 0; end elseif closestMatch == 4 % It thinks it is a U % Euler# can be 0 or 1 if (document_letter.EulerNumber ~=1 ) % Reject closestMatch = 0; end % Also, calculate the Eulers for the top and % bottom slices midpoint = floor(document_letter.BoundingBox(4)/2); topPart = im2bw(document_letter.Image(1:midpoint,:), 0.5); bottomPart = im2bw(document_letter.Image(midpoint+1,:), 0.5); topFeature = imfeature(double(topPart), 'EulerNumber'); bottomFeature = imfeature(double(bottomPart), 'EulerNumber'); topEuler = topFeature(1).EulerNumber; bottomEuler = bottomFeature(1).EulerNumber; % For u's, the top Euler number is 2, and the bottom % part has Euler number of 2 if (topEuler~=2) | (bottomEuler ~= 2) % Can't be an U according to Euler checks closestMatch = 0; end end result = closestMatch; else result = 0; end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值