小言_互联网的博客

【图像识别】基于RGB和BP神经网络的人民币识别系统含GUI界面

212人阅读  评论(0)
  • 课题介绍

    本设计为基于MATLAB的人民币识别系统。带有一个GUI界面。先利用radon进行倾斜校正,根据不同纸币,选择不同维度的参数识别纸币金额,有通过RGB分量识别100元;

通过面额图像的宽度识别1元、5元;通过构建矩形结构体识别10元 ;通过RGB分量识别 20元 与 50元。

 

1.1 图像识别技术原理

其实,图像识别技术背后的原理并不是很难,只是其要处理的信息比较繁琐。计算机的任何处理技术都不是凭空产生的,它都是学者们从生活实践中得到启发而利用程序将其模拟实现的。计算机的图像识别技术和人类的图像识别在原理上并没有本质的区别,只是机器缺少人类在感觉与视觉差上的影响罢了。人类的图像识别也不单单是凭借整个图像存储在脑海中的记忆来识别的,我们识别图像都是依靠图像所具有的本身特征而先将这些图像分了类,然后通过各个类别所具有的特征将图像识别出来的,只是很多时候我们没有意识到这一点。当看到一张图片时,我们的大脑会迅速感应到是否见过此图片或与其相似的图片。其实在“看到”与“感应到”的中间经历了一个迅速识别过程,这个识别的过程和搜索有些类似。在这个过程中,我们的大脑会根据存储记忆中已经分好的类别进行识别,查看是否有与该图像具有相同或类似特征的存储记忆,从而识别出是否见过该图像。机器的图像识别技术也是如此,通过分类并提取重要特征而排除多余的信息来识别图像。机器所提取出的这些特征有时会非常明显,有时又是很普通,这在很大的程度上影响了机器识别的速率。总之,在计算机的视觉识别中,图像的内容通常是用图像特征进行描述。

  1. 
        
    1. function varargout = main(varargin)
    2. % MAIN MATLAB code for main.fig
    3. % MAIN, by itself, creates a new MAIN or raises the existing
    4. % singleton*.
    5. %
    6. % H = MAIN returns the handle to a new MAIN or the handle to
    7. % the existing singleton*.
    8. %
    9. % MAIN('CALLBACK',hObject,eventData,handles,...) calls the local
    10. % function named CALLBACK in MAIN.M with the given input arguments.
    11. %
    12. % MAIN('Property','Value',...) creates a new MAIN or raises the
    13. % existing singleton*. Starting from the left, property value pairs are
    14. % applied to the GUI before main_OpeningFcn gets called. An
    15. % unrecognized property name or invalid value makes property application
    16. % stop. All inputs are passed to main_OpeningFcn via varargin.
    17. %
    18. % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
    19. % instance to run (singleton)".
    20. %
    21. % See also: GUIDE, GUIDATA, GUIHANDLES
    22. % Edit the above text to modify the response to help main
    23. % Last Modified by GUIDE v2.5 29-May-2020 00:04:07
    24. % Begin initialization code - DO NOT EDIT
    25. gui_Singleton = 1;
    26. gui_State = struct( 'gui_Name', mfilename, ...
    27. 'gui_Singleton', gui_Singleton, ...
    28. 'gui_OpeningFcn', @main_OpeningFcn, ...
    29. 'gui_OutputFcn', @main_OutputFcn, ...
    30. 'gui_LayoutFcn', [] , ...
    31. 'gui_Callback', []);
    32. if nargin && ischar(varargin{ 1})
    33. gui_State.gui_Callback = str2func(varargin{ 1});
    34. end
    35. if nargout
    36. [varargout{ 1:nargout}] = gui_mainfcn(gui_State, varargin{:});
    37. else
    38. gui_mainfcn(gui_State, varargin{:});
    39. end
    40. % End initialization code - DO NOT EDIT
    41. % --- Executes just before main is made visible.
    42. function main_OpeningFcn(hObject, eventdata, handles, varargin)
    43. % This function has no output args, see OutputFcn.
    44. % hObject handle to figure
    45. % eventdata reserved - to be defined in a future version of MATLAB
    46. % handles structure with handles and user data (see GUIDATA)
    47. % varargin command line arguments to main (see VARARGIN)
    48. % Choose default command line output for main
    49. handles.output = hObject;
    50. % Update handles structure
    51. guidata(hObject, handles);
    52. % UIWAIT makes main wait for user response (see UIRESUME)
    53. % uiwait(handles.figure1);
    54. % --- Outputs from this function are returned to the command line.
    55. function varargout = main_OutputFcn(hObject, eventdata, handles)
    56. % varargout cell array for returning output args (see VARARGOUT);
    57. % hObject handle to figure
    58. % eventdata reserved - to be defined in a future version of MATLAB
    59. % handles structure with handles and user data (see GUIDATA)
    60. % Get default command line output from handles structure
    61. varargout{ 1} = handles.output;
    62. % --- Executes on button press in pushbutton1.
    63. function pushbutton1_Callback(hObject, eventdata, handles)
    64. % hObject handle to pushbutton1 (see GCBO)
    65. % eventdata reserved - to be defined in a future version of MATLAB
    66. % handles structure with handles and user data (see GUIDATA)
    67. %% 图像读取
    68. [filename, pathname] = uigetfile({ '*.jpg;*.tif;*.png;*.gif', 'All Image Files';...
    69. '*.*', 'All Files' });
    70. l = imread([ pathname,filename]);
    71. axes(handles.axes1)
    72. imshow(l);
    73. title( '原始图像')
    74. l1=rgb2gray(l); %将真彩色图像转换为灰度图像
    75. bw1=edge(l1, 'sobel', 'both'); %采用sobel算子进行边缘检测
    76. handles.bw1=bw1;
    77. theta= 0: 179; %定义theta角度范围
    78. r=radon(bw1,theta); %对图像进行Radon变换
    79. %%%%%检测Radon变换矩阵中的峰值所对应的列坐标%%%%
    80. [m,n]=size(r);
    81. c= 1;
    82. for i= 1:m
    83. for j= 1:n
    84. if r( 1, 1)<r(i,j)
    85. r( 1, 1)=r(i,j);
    86. c=j;
    87. end
    88. end
    89. end
    90. rot= 90-c;
    91. %%
    92. %%%%%%求纸币列起始位置和终止位置%%%%%
    93. PY1=MaxY;
    94. while ((Y1(PY1, 1)>= 50)&&(PY1> 1))
    95. PY1=PY1- 1;
    96. end
    97. PY2=MaxY;
    98. while ((Y1(PY2, 1)>= 50)&&(PY2<y))
    99. PY2=PY2+ 1;
    100. end
    101. IY=pic(PY1:PY2,:,:);
    102. X1=zeros( 1,x);
    103. for j= 1:x
    104. for i=PY1:PY2
    105. if(I6(i,j, 1)== 1)
    106. X1( 1,j)= X1( 1,j)+ 1;
    107. end
    108. end
    109. end
    110. %%
    111. %%提取并画出背景中的RMB图像%%
    112. PX1= 1;
    113. while ((X1( 1,PX1)< 3)&&(PX1<x))
    114. PX1=PX1+ 1;
    115. end
    116. PX2=x;
    117. while ((X1( 1,PX2)< 3)&&(PX2>PX1))
    118. PX2=PX2- 1;
    119. end
    120. dw=pic(PY1:PY2,PX1:PX2,:);
    121. dw_gray=rgb2gray(dw);
    122. dw_gray=imadjust(dw_gray,[ 0, 1],[ 1, 0]);
    123. dw_bw=im2bw(dw_gray);
    124. handles.dw_bw=dw_bw;
    125. %%
    126. %%分割提取RMB数值图像%%
    127. [m,n]=size(dw_bw);
    128. m1=round(m/ 3);
    129. m2=round( 2*m/ 3);
    130. n1=round(n/ 6);
    131. n2=round(n/ 3);
    132. n3=round( 2*n/ 3);
    133. n4=round( 5*n/ 6);
    134. sum1=sum(sum(dw_bw(m1:m2,n1:n2)));
    135. sum2=sum(sum(dw_bw(m1:m2,n3:n4)));
    136. if sum1>sum2
    137. dw=imrotate(dw, 180, 'crop');
    138. end
    139. %%
    140. %%图像处理%%
    141. x=dw;
    142. x1=imresize(x,[ 236, 500]); %'缩放图像
    143. z=imcrop(x1,[ 270, 150, 160, 65]); %对图像进行剪切,选取有效区域
    144. %%
    145. I=imcrop(x1,[ 130, 60, 130, 65]); %对图像进行剪切,选取有效区域
    146. handles.I=I;
    147. I1=rgb2gray(I); %转换为灰度图像
    148. I2=medfilt2(I1); %滤波默认窗口
    149. I3=imadjust(I2,[ 0.3, 0.5],[ 0, 1], 1); %明暗反转
    150. I4=im2bw(I3);
    151. handles.I4=I4;
    152. se=strel( 'rectangle',[ 3, 3]); %构造结构函数,以长方形构造一个se

     

    完整代码或者代写添加QQ1575304183


转载:https://blog.csdn.net/weixin_50197058/article/details/116505447
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场