一、课题介绍
本设计为基于MATLAB的人民币识别系统。带有一个GUI界面。先利用radon进行倾斜校正,根据不同纸币,选择不同维度的参数识别纸币金额,有通过RGB分量识别100元;
通过面额图像的宽度识别1元、5元;通过构建矩形结构体识别10元 ;通过RGB分量识别 20元 与 50元。
二、运行GUI界面设计
     
     
     
function ima = getImage()
[filename, pathname] = uigetfile({'*.jpg;*.tif;*.png;*.gif','All Image Files';...
          '*.*','All Files' });
ima = imread([ pathname,filename]);
2、对纸币进行radon旋转矫正
l1=rgb2gray(l);                %将真彩色图像转换为灰度图像
bw1=edge(l1,'sobel', 'both');  %采用sobel算子进行边缘检测
theta=0:179;                   %定义theta角度范围
r=radon(bw1,theta);            %对图像进行Radon变换
%%%%%检测Radon变换矩阵中的峰值所对应的列坐标%%%%
[m,n]=size(r);
c=1;
for i=1:m
    for j=1:n
        if  r(1,1)<r(i,j)
           r(1,1)=r(i,j);
            c=j;
        end
    end
end
rot=90-c;
pic=imrotate(l,rot,'crop');                     %对图片进行旋转矫正
3、纸币图像预处理
pic_gray=rgb2gray(pic);                         %转换为灰度图像
pic_a=imadjust(pic_gray,[0,0.001],[1,0]);       %明暗反转
pic_b=1.3*pic_gray+0.7*pic_a;
pic_c=imadjust(pic_b,[0.5,1],[0,1]);            %明暗反转
pic_b_edge=edge(pic_c,'sobel');                 %采用sobel算子进行边缘检测
se=[1;1;1];                                     %线型结构元素
pic_imerode=imerode(pic_b_edge,se);             %腐蚀图像
se=strel('rectangle',[60,60]);                  %矩形结构元素
pic_imclose=imclose(pic_imerode,se);            %图像聚类、填充图像
pic_bwareaopen=bwareaopen(pic_imclose,10000);   %去除聚团灰度值小于10000的部分
4、得到纸币数字位置定位
%%%%%求纸币行起始位置和终止位置%%%%%
[y,x]=size(pic_bwareaopen);
I6=double(pic_bwareaopen);
Y1=zeros(y,1);
 for i=1:y
    for j=1:x
             if(I6(i,j,1)==1)
                Y1(i,1)= Y1(i,1)+1;
            end
     end
 end
[temp MaxY]=max(Y1);
%%
%%%%%%求纸币列起始位置和终止位置%%%%%
PY1=MaxY;
 while ((Y1(PY1,1)>=50)&&(PY1>1))
        PY1=PY1-1;
 end
 PY2=MaxY;
 while ((Y1(PY2,1)>=50)&&(PY2<y))
        PY2=PY2+1;
 end
 IY=pic(PY1:PY2,:,:);
 X1=zeros(1,x);
 for j=1:x
     for i=PY1:PY2
            if(I6(i,j,1)==1)
                X1(1,j)= X1(1,j)+1;
            end
     end
 end
5、判断数字宽度
%%%通过图像RGb分量判断RMB币值
if averageR-averageG>35
 result=100;
else
    [m,n]=size(I6);
 %通过提取出的数值图像的大小 来判断币值
    if(n<=90)
         result=1; %一位数值宽度
    end
    if(n>90&&n<165)
         result=5; %一位数值宽度
    end
    if(n>310)
         result=100;%三位数值宽度
    end
6、数值识别
 if(n>=165&&n<310)
        I7=I4(:,X1:X2);%I7
        se=strel('rectangle',[35,5]);
        I8=imdilate(I7,se);
        I9=imerode(I8,se);
        I10=~I9;
        [M,N]=size(I10);
        M1=round(M/3);
        M2=round(2*M/3);
        N1=round(N/2);
        ui1=sum(sum(I10(1:M1,1:N1)));
        ui2=sum(sum(I10(M1:M2,1:N1)));
        ui3=sum(sum(I10(M2:M,1:N1)));
        if(ui1>25&&ui2>150&&ui3>25)
             result=10;