一、简介

基于matlab GUI二维条形码的识别

二、源代码

function varargout = untitled(varargin)
% UNTITLED M-file for untitled.fig
%      UNTITLED, by itself, creates a new UNTITLED or raises the existing
%      singleton*.
%
%      H = UNTITLED returns the handle to a new UNTITLED or the handle to
%      the existing singleton*.
%
%      UNTITLED('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in UNTITLED.M with the given input arguments.
%
%      UNTITLED('Property','Value',...) creates a new UNTITLED or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before untitled_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to untitled_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 untitled% Last Modified by GUIDE v2.5 03-Nov-2011 13:59:22% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...'gui_Singleton',  gui_Singleton, ...'gui_OpeningFcn', @untitled_OpeningFcn, ...'gui_OutputFcn',  @untitled_OutputFcn, ...'gui_LayoutFcn',  [] , ...'gui_Callback',   []);
if nargin && ischar(varargin{1})gui_State.gui_Callback = str2func(varargin{1});
endif nargout[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
elsegui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT% --- Executes just before untitled is made visible.
function untitled_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 untitled (see VARARGIN)% Choose default command line output for untitled
handles.output = hObject;
image1=imread('C:\Users\lenovo\Desktop\61602302barcodehcc\barcodehcc\1.bmp');
axes(handles.axes1);
imshow(image1);% Update handles structure
guidata(hObject, handles);% UIWAIT makes untitled wait for user response (see UIRESUME)
% uiwait(handles.figure1);% --- Outputs from this function are returned to the command line.
function varargout = untitled_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 mouse press over axes background.% --- 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)global im;
%提取条形码区域构成的矩形的左上角坐标
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
image=im;
l1=rgb2gray(image);
level=graythresh(l1);
l2=im2bw(l1,level);
l3=~l2;
l4=bwareaopen(l3,50);
l5=~l4;
l6=edge(l1,'canny');
l7=imclose(l6,strel('rectangle',[2,19]));
l8=imopen(l7,strel('rectangle',[2,19]));
l9=imopen(l8,strel('rectangle',[2,19]));
[L,num]=bwlabel(l9,8);
STATS=regionprops(L,'all');
a=length(STATS);
%figure,imshow(L);
%hold on;
b=0;
for i=1:atemp=STATS(i).BoundingBox;s=temp(3)*temp(4);if s>bb=s;k=i;%记录面积最大的标记区域的索引值end
end
%rectangle('position',STATS(k).BoundingBox,'edgecolor','r');%绘制最大标记区域的外接矩形
temp=STATS(k).BoundingBox;
Rx=round(temp(1));Ry=round(temp(2));%提取条形码区域左上角的坐标
Rwidth=round(temp(3));Rlength=round(temp(4));%初始化
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
check_left = [13,25,19,61,35,49,47,59,55,11;...    %左边数据编码,奇39,51,27,33,29,57, 5,17, 9,23]; %左边数据编码,偶
check_right = [114,102,108,66,92,78,80,68,72,116]; %右边数据编码
first_num = [31,20,18,17,12,6,3,10,9,5];    %第一位数据编码
bar = im;  %读输入条形码图片
bar_Gray = rgb2gray(bar);   %将RGB图片转换灰度图[a_hist x] = imhist(bar_Gray);   %绘制灰度直方图,返回直方图数据向量a_hist,和相应的色彩值向量x%寻找进行二值化处理的阈值,存放在T中
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%hist_max = [];
if a_hist(1)>a_hist(2)hist_max = [hist_max 1];
end
x = max(x);
for i=2:xif a_hist(i)>a_hist(i-1) && a_hist(i)>a_hist(i+1)hist_max = [hist_max i];end
end
if a_hist(x)<a_hist(x+1)hist_max = [hist_max x+1];
end
[m,n] = size(hist_max);
k = 0;
max_1 = 0;
max_2 = 0;
for i=1:nif k<a_hist(hist_max(i))k = a_hist(hist_max(i));max_1 = hist_max(i);end
end
temp = a_hist(max_1);
a_hist(max_1) = 0;
k = 0;
for i=1:nif k<a_hist(hist_max(i))k = a_hist(hist_max(i));max_2 = hist_max(i);end
end
a_hist(max_1) = temp;
if max_1>max_2k = max_1;max_1 = max_2;max_2 = k;
end
T = max_1;
k = a_hist(max_1);
for i=max_1:max_2if k>a_hist(i)k = a_hist(i);T = i;end
end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%[m,n] = size(bar_Gray); %求灰度图的大小
for i=1:m        %对图像进行二值化处理for j=1:nif bar_Gray(i,j)>T    %选择适当的阈值进行二值化处理bar_10(i,j) = 1;elsebar_10(i,j) = 0;endend
end

三、运行结果


【图像识别】基于二维条形码识别matlab 源码含GUI相关推荐

  1. 【语音识别】基于mfcc特征模板匹配算法实现声纹识别matlab源码含GUI

    在任意一个Automatic speech recognition 系统中,第一步就是提取特征.换句话说,我们需要把音频信号中具有辨识性的成分提取出来,然后把其他的乱七八糟的信息扔掉,例如背景噪声啊, ...

  2. 【人脸识别】基于 Gabor+SVM和PCA+SVM实现人脸识别matlab源码含 GUI

    1 简介 随着经济的快速发展,互联网的普及,信息安全逐渐被人们所重视.人脸识别技术作为保护信息安全的重要手段之一,也逐渐被研究学者所重视.人脸识别作为计算机视觉技术和生物特征识别技术的一个重要分支,模 ...

  3. 【通信】基于短波通信系统仿真matlab源码含 GUI

    一.简介 短波按照国际无线电咨询委员会(CCIR,现在的ITU-R)的划分是指波长在l00ml0m,频率为3MHz30MHz的电磁波.利用短波进行的无线电通信称为短波通信,又称高频(HF)通信.实际上 ...

  4. 【身份证识别】基于形态学实现二代身份证号码识别系统matlab源码含GUI

    一.简介 首先从身份证图像上获取0-9和X共十一个号码字符的样本图像作为后续识别的字符库样本,其次将待测身份证图像进行去噪.灰度化.二值化.水平投影切割,垂直投影并切割,将待测身份证号码分割出来,然后 ...

  5. 【图像识别】基于 Haar分类器实现五官定位matlab源码含 GUI

    一.简介 1 Haar分类器的前世今生 人脸检测属于计算机视觉的范畴,早期人们的主要研究方向是人脸识别,即根据人脸来识别人物的身份,后来在复杂背景下的人脸检测需求越来越大,人脸检测也逐渐作为一个单独的 ...

  6. 【身份证识别】基于形态学实现ID号码识别系统matlab源码含GUI

    一.简介 模型参考这里. 二.源代码 function varargout = id_rec_gui(varargin) % ID_REC_GUI MATLAB code for id_rec_gui ...

  7. 【图像识别】基于HSV和RGB模型水果分类matlab源码含 GUI

    一.简介 1 RGB颜色空间: RGB(red,green,blue)颜色空间最常用的用途就是显示器系统(计算机.电视机等都是采用RGB颜色空间来进行图像显示).一般来说,电脑,电视机等是利用三个电子 ...

  8. 【人脸识别】基于PCA+SVM人脸识别(准确率)matlab源码含GUI

    一.简介 1 PCA\ PCA(Principal Component Analysis)是常用的数据分析方法.PCA是通过线性变换,将原始数据变换为一组各维度线性无关的数据表示方法,可用于提取数据的 ...

  9. 【图像配准】基于Horn-Schunck和Lucas-Kanade等光流场实现图像配准matlab源码含GUI界面

    光流法理论背景 1.什么是光流 光流(optical flow)是空间运动物体在观察成像平面上的像素运动的瞬时速度. 光流法是利用图像序列中像素在时间域上的变化以及相邻帧之间的相关性来找到上一帧跟当前 ...

最新文章

  1. python scipy卷积 图像卷积
  2. poi写入Excel
  3. matplotlib 知识点整理:ax与figure
  4. 天翼云从业认证(4.10)网络直播场景解决方案(CDN)
  5. 设计一个可扩展的用户登录系统
  6. linkedin爬虫_机器学习的学生和从业者的常见问题在LinkedIn上提问
  7. 列表和range、元组
  8. 数据特征分析:2.对比分析
  9. uniapp 中 下拉刷新和上拉加载 需要手动在page.json中开启
  10. 微信小程序 this和that详解及简单实例
  11. MATLAB偏振光的反射与折射,仿真程序动画作品--光的反射与折射*
  12. python sklearn svm 权重_sklearn svm基本使用
  13. EasyUI的DataGrid 分页栏英文改中文解决方案
  14. 前端后台学习笔记汇杂
  15. 配置百度云CDN加速
  16. 集成电路封测行业科普
  17. Java多线程编程模式实战指南(一):Active Object模式--转载
  18. Bluefish 1.1.3
  19. jsp主机与asp主机的区别和支持分析
  20. 关于浏览器被劫持主页的处理方法(完结版)

热门文章

  1. Ubuntu18.04安装anaconda+tensorflow2.0(GPU)、显卡驱动、搜狗输入法、TIM
  2. U盘装完ubuntu20.04后需要注意的,解决输入法和login loop问题等
  3. JS实用技巧之断点调试详解
  4. 双十一还在线上购物?线下实体店数字化转型带来新机遇
  5. 重庆计算机应用学校,重庆财政学校-计算机应用
  6. 如何使用proxyTable
  7. 5s邮箱怎么总是连不上服务器,outlook 经常连不到exchange 服务器
  8. SSM整合(Spring + SpringMVC + Mybatis)
  9. transformer做文本分类的keras实现完整版
  10. Linux中使用命令行删除目录