【图像识别】基于模板匹配之手写数字识别系统GUI界面

人类文明的发展离不开信息的传递。文字一直是人们传递信息的一个重要媒介,承载着记录人类文明的重要使命。随着科技的发展,积累的文字信息日益增多,有效的存储和利用这些文字信息成为一个亟待解决的问题。光学字符识别的出现为这一问题提供了解决方法。手写体数字识别是光学字符识别的重要分支,因其在金融、邮政、医疗、交通、教育等领域中广泛的应用而日益被重视。目前,已有多种手写体数字识别算法,但都很难满足手写体数字识别应用时对识别率近乎百分之百的要求,所以,几乎没有能够实际应用的识别算法。 本文针对手写体数字识别对正确识别率及识别精度要求高的问题,在图像模式识别的理论基础上提出了一种基于数字字符几何轮廓特征的模板匹配改进算法,并利用该识别算法实现了针对医院信息统计表和医院处方笺的手写体字符识别信息录入系统。具体工作内容如下: (1)提出基于模板匹配的手写体字符识别算法。该算法考虑数字字符笔画简单的特点,以字符的质心为参考中心,利用字符的整体几何轮廓特征作为分类的依据,提取距离向量作为特征,使用改进的模板匹配算法设计分类器来进行字符识别。引入缩放因子和变异系数进行分类判别,增加了分类的准确性和可靠性。在样本库的设计上有所改进,采用多种标准字体书写的数字字符作为模板,减小了样本库的规模。 (2)利用matlab编程软件实现了手写体字符识别信息录入系统。在系统中设计了针对医院信息统计表和校医院处方笺中手写体字符的定位提取算法、多字符分割算法,可自动完成字符的提取、识别、结果输出和自动存储等多种功能。 (3)采集不同人群的手写体字符作为样本对算法进行验证。实验结果表明,本文提出的算法获得了较高的识别率,识别速度快,具有一定的抗噪能力,对待测字符的大小和位置的具有良好的鲁棒性,且具有较高的可行性和有效性,在本文所设计的信息录入系统中应用良好。

模板匹配的工作方式
    模板匹配的工作方式跟直方图的反向投影基本一样,大致过程是这样的:通过在输入图像上滑动图像块对实际的图像块和输入图像进行匹配。
    假设我们有一张100x100的输入图像,有一张10x10的模板图像,查找的过程是这样的:
  (1)从输入图像的左上角(0,0)开始,切割一块(0,0)至(10,10)的临时图像;
  (2)用临时图像和模板图像进行对比,对比结果记为c;
  (3)对比结果c,就是结果图像(0,0)处的像素值;
  (4)切割输入图像从(0,1)至(10,11)的临时图像,对比,并记录到结果图像;
  (5)重复(1)~(4)步直到输入图像的右下角。
    大家可以看到,直方图反向投影对比的是直方图,而模板匹配对比的是图像的像素值;模板匹配比直方图反向投影速度要快一些,但是我个人认为直方图反向投影的鲁棒性会更好。

  1. function varargout = daunxujian1(varargin)
    % DAUNXUJIAN1 MATLAB code for daunxujian1.fig
    %      DAUNXUJIAN1, by itself, creates a new DAUNXUJIAN1 or raises the existing
    %      singleton*.
    %
    %      H = DAUNXUJIAN1 returns the handle to a new DAUNXUJIAN1 or the handle to
    %      the existing singleton*.
    %
    %      DAUNXUJIAN1('CALLBACK',hObject,eventData,handles,...) calls the local
    %      function named CALLBACK in DAUNXUJIAN1.M with the given input arguments.
    %
    %      DAUNXUJIAN1('Property','Value',...) creates a new DAUNXUJIAN1 or raises the
    %      existing singleton*.  Starting from the left, property value pairs are
    %      applied to the GUI before daunxujian1_OpeningFcn gets called.  An
    %      unrecognized property name or invalid value makes property application
    %      stop.  All inputs are passed to daunxujian1_OpeningFcn via varargin.
    %
    %      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
    %      instance to run (singleton)".
    %
    % See also: GUIDE, GUIDATA, GUIHANDLES
     
    % Edit the above text to modify the response to help daunxujian1
     
    % Last Modified by GUIDE v2.5 23-Oct-2020 21:52:34
     
    % Begin initialization code - DO NOT EDIT
    gui_Singleton = 1;
    gui_State = struct('gui_Name',       mfilename, ...
                       'gui_Singleton',  gui_Singleton, ...
                       'gui_OpeningFcn', @daunxujian1_OpeningFcn, ...
                       'gui_OutputFcn',  @daunxujian1_OutputFcn, ...
                       'gui_LayoutFcn',  [] , ...
                       'gui_Callback',   []);
    if nargin && ischar(varargin{1})
        gui_State.gui_Callback = str2func(varargin{1});
    end
     
    if nargout
        [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
    else
        gui_mainfcn(gui_State, varargin{:});
    end
    % End initialization code - DO NOT EDIT
     
     
    % --- Executes just before daunxujian1 is made visible.
    function daunxujian1_OpeningFcn(hObject, eventdata, handles, varargin)
    % This function has no output args, see OutputFcn.
    % hObject    handle to figure
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)
    % varargin   command line arguments to daunxujian1 (see VARARGIN)
    % Choose default command line output for daunxujian1
    handles.output = hObject;
    handles.Result = [];
    handles.File = [];
    % Update handles structure
    guidata(hObject, handles);
    clc; warning off all;
    InitAxes(handles);
    % UIWAIT makes daunxujian1 wait for user response (see UIRESUME)
    % uiwait(handles.figure1);
     
     
    % --- Outputs from this function are returned to the command line.
    function varargout = daunxujian1_OutputFcn(hObject, eventdata, handles) 
    % varargout  cell array for returning output args (see VARARGOUT);
    % hObject    handle to figure
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)
     
    % Get default command line output from handles structure
    varargout{1} = handles.output;
     
     
    % --- Executes on button press in pushbutton1.
    function pushbutton1_Callback(hObject, eventdata, handles)
    % hObject    handle to pushbutton1 (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)
    [filename, pathname] = uigetfile({'*.jpg;*.tif;*.png;*.gif','All Image Files';...
        '*.*','All Files' },'载入图像',...
        fullfile(pwd, 'images'));
    I = imread(fullfile(pathname, filename));
    Result = Process_Main(I);
    handles.File = fullfile(pathname, filename);
    handles.Result = Result;
    guidata(hObject, handles);
    InitAxes(handles)
    axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
     
    % --- Executes on button press in pushbutton2.
    function pushbutton2_Callback(hObject, eventdata, handles)
    % hObject    handle to pushbutton2 (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)
    if ~isempty(handles.Result)
        axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
        axes(handles.axes2); imshow(handles.Result.Medfilt); title('中值滤波图像');
    end
     
    % --- Executes on button press in pushbutton3.
    function pushbutton3_Callback(hObject, eventdata, handles)
    % hObject    handle to pushbutton3 (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)
    if ~isempty(handles.Result)
        axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
        axes(handles.axes2); imshow(handles.Result.Medfilt); title('中值滤波图像');
        axes(handles.axes3); imshow(handles.Result.Normalize); title('归一化图像');
    end
     
    % --- Executes on button press in pushbutton4.
    function pushbutton4_Callback(hObject, eventdata, handles)
    % hObject    handle to pushbutton4 (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)
    if ~isempty(handles.Result)
        axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
        axes(handles.axes2); imshow(handles.Result.Medfilt); title('中值滤波图像');
        axes(handles.axes3); imshow(handles.Result.Normalize); title('归一化图像');
        axes(handles.axes4); imshow(handles.Result.Bww); title('二值化图像');
    end
     
    % --- Executes on button press in pushbutton6.
    function pushbutton6_Callback(hObject, eventdata, handles)
    % hObject    handle to pushbutton6 (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)
    if ~isempty(handles.Result)
        axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
        axes(handles.axes2); imshow(handles.Result.Medfilt); title('中值滤波图像');
        axes(handles.axes3); imshow(handles.Result.Normalize); title('归一化图像');
        axes(handles.axes4); imshow(handles.Result.Bww); title('二值化图像');
        axes(handles.axes6); imshow(handles.Result.Thin); title('细化处理');
        axes(handles.axes5); imshow(handles.Result.Bw); title('特征提取');
        hold on;
        h = [];
        for i = 1 : length(handles.Result.hs) %绘制水平线
            h = [h plot([1 handles.Result.sz(2)], [handles.Result.hs(i) handles.Result.hs(i)], 'r-')];
        end
        for i = 1 : length(handles.Result.vs)%绘制竖直线
            h = [h plot([handles.Result.vs(i) handles.Result.vs(i)], [1 handles.Result.sz(1)], 'g-')];
        end
        h = [h plot(handles.Result.x1, handles.Result.y1, 'y-')];%绘制左对角线
        h = [h plot(handles.Result.x2, handles.Result.y2, 'm-')];%绘制右对角线
    end
     
    % --- Executes on button press in pushbutton7.
    function pushbutton7_Callback(hObject, eventdata, handles)
    % hObject    handle to pushbutton7 (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)
    [filename, pathname] = uiputfile({'*.jpg;*.tif;*.png;*.gif','All Image Files';...
        '*.*','All Files' },'Save Image',...
        fullfile(pwd, 'Result/result.png'));
    if ~isequal(filename, 0)
        imwrite(handles.Result.label, fullfile(pathname, filename));
        msgbox('保存图像成功!', '信息提示框');
    end
     
     
    % --- Executes on button press in pushbutton9.
    function pushbutton9_Callback(hObject, eventdata, handles)
    % hObject    handle to pushbutton9 (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)
    choice = questdlg('确定退出?', ...
        '退出', ...
        '是','否','否');
    switch choice
        case '是'
            close;
        otherwise
            return;
    end
     
     
    function edit1_Callback(hObject, eventdata, handles)
    % hObject    handle to edit1 (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)
     
    % Hints: get(hObject,'String') returns contents of edit1 as text
    %        str2double(get(hObject,'String')) returns contents of edit1 as a double
     
     
    % --- Executes during object creation, after setting all properties.
    function edit1_CreateFcn(hObject, eventdata, handles)
    % hObject    handle to edit1 (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    empty - handles not created until after all CreateFcns called
     
    % Hint: edit controls usually have a white background on Windows.
    %       See ISPC and COMPUTER.
    if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
        set(hObject,'BackgroundColor','white');
    end
     
     
    % --- Executes on button press in pushbutton8.
    function pushbutton8_Callback(hObject, eventdata, handles)
    % hObject    handle to pushbutton8 (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)
    set(handles.edit1,'string',handles.Result.label);
     
     
    % --- Executes on button press in pushbutton10.
    function pushbutton10_Callback(hObject, eventdata, handles)
    % hObject    handle to pushbutton10 (see GCBO)
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)
    if ~isempty(handles.Result)
        axes(handles.axes1); imshow(handles.Result.Image); title('原图像');
        axes(handles.axes2); imshow(handles.Result.Medfilt); title('中值滤波图像');
        axes(handles.axes3); imshow(handles.Result.Normalize); title('归一化图像');
        axes(handles.axes4); imshow(handles.Result.Bww); title('二值化图像');
        axes(handles.axes6); imshow(handles.Result.Thin); title('细化处理');
    end

    🎈 部分理论引用网络文献,若有侵权联系博主删除
    🎁  关注我领取海量matlab电子书和数学建模资料

    👇  私信完整代码和数据获取及论文数模仿真定制

    1 各类智能优化算法改进及应用
    生产调度、经济调度、装配线调度、充电优化、车间调度、发车优化、水库调度、三维装箱、物流选址、货位优化、公交排班优化、充电桩布局优化、车间布局优化、集装箱船配载优化、水泵组合优化、解医疗资源分配优化、设施布局优化、可视域基站和无人机选址优化、背包问题、 风电场布局、时隙分配优化、 最佳分布式发电单元分配、多阶段管道维修、 工厂-中心-需求点三级选址问题、 应急生活物质配送中心选址、 基站选址、 道路灯柱布置、 枢纽节点部署、 输电线路台风监测装置、 集装箱船配载优化、 机组优化、 投资优化组合、云服务器组合优化、 天线线性阵列分布优化、CVRP问题、VRPPD问题、多中心VRP问题、多层网络的VRP问题、多中心多车型的VRP问题、 动态VRP问题、双层车辆路径规划(2E-VRP)、充电车辆路径规划(EVRP)、油电混合车辆路径规划、混合流水车间问题、 订单拆分调度问题、 公交车的调度排班优化问题、航班摆渡车辆调度问题、选址路径规划问题
    2 机器学习和深度学习方面

    2.1 bp时序、回归预测和分类

    2.2 ENS声神经网络时序、回归预测和分类

    2.3 SVM/CNN-SVM/LSSVM/RVM支持向量机系列时序、回归预测和分类

    2.4 CNN/TCN卷积神经网络系列时序、回归预测和分类

    2.5 ELM/KELM/RELM/DELM极限学习机系列时序、回归预测和分类
    2.6 GRU/Bi-GRU/CNN-GRU/CNN-BiGRU门控神经网络时序、回归预测和分类

    2.7 ELMAN递归神经网络时序、回归\预测和分类

    2.8 LSTM/BiLSTM/CNN-LSTM/CNN-BiLSTM/长短记忆神经网络系列时序、回归预测和分类

    2.9 RBF径向基神经网络时序、回归预测和分类

    2.10 DBN深度置信网络时序、回归预测和分类
    2.11 FNN模糊神经网络时序、回归预测
    2.12 RF随机森林时序、回归预测和分类
    2.13 BLS宽度学习时序、回归预测和分类
    2.14 PNN脉冲神经网络分类
    2.15 模糊小波神经网络预测和分类
    2.16 时序、回归预测和分类
    2.17 时序、回归预测预测和分类
    2.18 XGBOOST集成学习时序、回归预测预测和分类
    方向涵盖风电预测、光伏预测、电池寿命预测、辐射源识别、交通流预测、负荷预测、股价预测、PM2.5浓度预测、电池健康状态预测、用电量预测、水体光学参数反演、NLOS信号识别、地铁停车精准预测、变压器故障诊断
    2.图像处理方面
    图像识别、图像分割、图像检测、图像隐藏、图像配准、图像拼接、图像融合、图像增强、图像压缩感知
    3 路径规划方面
    旅行商问题(TSP)、车辆路径问题(VRP、MVRP、CVRP、VRPTW等)、无人机三维路径规划、无人机协同、无人机编队、机器人路径规划、栅格地图路径规划、多式联运运输问题、 充电车辆路径规划(EVRP)、 双层车辆路径规划(2E-VRP)、 油电混合车辆路径规划、 船舶航迹规划、 全路径规划规划、 仓储巡逻
    4 无人机应用方面
    无人机路径规划、无人机控制、无人机编队、无人机协同、无人机任务分配、无人机安全通信轨迹在线优化、车辆协同无人机路径规划
    5 通信方面
    传感器部署优化、通信协议优化、路由优化、目标定位优化、Dv-Hop定位优化、Leach协议优化、WSN覆盖优化、组播优化、RSSI定位优化、水声通信
    6 信号处理方面
    信号识别、信号加密、信号去噪、信号增强、雷达信号处理、信号水印嵌入提取、肌电信号、脑电信号、信号配时优化、心电信号、DOA估计、编码译码、变分模态分解、管道泄漏、滤波器、数字信号处理+传输+分析+去噪、数字信号调制、误码率、信号估计、DTMF、信号检测
    7 电力系统方面
    微电网优化、无功优化、配电网重构、储能配置、有序充电
    8 元胞自动机方面
    交通流 人群疏散 病毒扩散 晶体生长 金属腐蚀
    9  雷达方面
    卡尔曼滤波跟踪、航迹关联、航迹融合、SOC估计

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
数字识别是一个重要的计算机视觉应用,通过基于模板匹配的方法可以实现数字的自动识别。 基于模板匹配数字识别方法主要包括以下几个步骤: 1. 数据准备:首先需要准备一组带有已知数字的训练样本,这些样本可以是数字图像。可以使用公开的数字数据库如MNIST来进行训练。 2. 特征提取:对于每个数字样本,我们需要提取一组特征作为数字的表示。常用的特征提取方法包括像素值、形态学特征和投影特征等。 3. 模板生成:根据训练样本,通过特征提取得到每个数字的特征向量,再根据一定的规则生成代表每个数字模板模板可以是一组数字特征的平均值或者是一组特殊选择的样本。 4. 模板匹配:对于待识别数字,同样先进行特征提取,然后将其特征向量与所有数字模板进行匹配。可以使用欧式距离、相关系数等度量方式来计算相似度,选择最相似的模板识别结果。 基于模板匹配数字识别方法的优点是简单易懂,计算速度快;缺点是对于不同的人相同数字样式的不一致性较为敏感,也难以应对方式、大小、旋转等因素的变化。 在实际应用中,可以结合其他识别方法如卷积神经网络(CNN)等来提升识别准确率。同时,还可以使用数据增强、特征选择、模型优化等技术段来改进基于模板匹配数字识别方法。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值