matlab一维条形码码字识别程序

更新时间:2023-07-20 19:27:47 阅读: 评论:0

matlab⼀维条形码码字识别程序clo all
I = imread('E:\txm.jpg');
J= rgb2gray(I);
figure(1)
imshow(J);
title('灰度化图像 ');
[e1,e2]=size(J);
Im=imcrop(J,[e2/2-200,e1/2-200,400,400]); figure(2)
subplot(1,2,1),imshow(Im)
title('中⼼区域 ');
subplot(1,2,2),imhist(Im)
title('中⼼区域直⽅图');
[xa,ya]=size(Im);
b=double(Im);
zd=double(max(Im)) ;
zx=double(min(Im)) ;
T=double((zd+zx))/2;
count=double(0);
蒜苗炒什么好吃while 1
count=count+1;
S0=0.0; n0=0.0;
S1=0.0; n1=0.0;
for i=1:xa
for j=1:ya
if double(Im(i,j))>=T
S1=S1+double(Im(i,j));
n1=n1+1;
el
S0=S0+double(Im(i,j));
n0=n0+1;
end
end
end
T0=S0/n0;
T1=S1/n1;
if abs(T-((T0+T1)/2))<0.1
break;
el
T=(T0+T1)/2;
安全保卫工作职责end
end
count
T
K=find(J
J(K)=0;
K=find(J>=T);
J(K)=255;
figure(3)
imshow(J)
title(' 图像⼆值化 ');
B=medfilt2(J,[5,1]);
figure(4)
imshow(B)
title('中值滤波后图像');
[y0,x0]=size(B);
BW = edge(B,'log');
figure(5);imshow(BW);title('边缘检测图像')
%function code = barcode(pic) %条形码识别
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 = imread('E:\txm.jpg');%读输⼊条形码图⽚
邓成波bar_Gray = rgb2gray(bar);%将RGB图⽚转换灰度图
[a_hist x] = imhist(bar_Gray);
hist_max = [];
if a_hist(1)>a_hist(2)
hist_max = [hist_max 1];
end
x = max(x);
for i=2:x
if 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)
hist_max = [hist_max x+1];
end
[m,n] = size(hist_max);
k = 0;
max_1 = 0;
max_2 = 0;
for i=1:n
if k
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:n
if k
k = a_hist(hist_max(i));
max_2 = hist_max(i);
end
小学生感恩演讲稿end
a_hist(max_1) = temp;
if max_1>max_2
k = max_1;
max_1 = max_2;
max_2 = k;
end
T = max_1;
k = a_hist(max_1);
for i=max_1:max_2
k = a_hist(i);
T = i;
end西式糕点
end
[m,n] = size(bar_Gray); %求灰度图的⼤⼩for i=1:m %对图像进⾏⼆值化处理
for j=1:n
if bar_Gray(i,j)>T%选择适当的阈值进⾏⼆值化处理
bar_10(i,j) = 1;
el
bar_10(i,j) = 0;
end
end
end
%imshow(bar_10);
l = 0;%检测59根条形码
for i=1:m
k = 1;
l = l+1;
for j=1:n-1
if bar_10(i,j)~=bar_10(i,j+1)%⽐较同⼀⾏相邻两点的颜⾊是否⼀致%bar_x(l,k) = i; bar_y(l,k) = j; %记录转折点的纵坐标
k = k+1;%准备记录下⼀个数据点
end
if k>61 %点数⼤于60,该⾏应该删掉
l = l-1;
break
end
end
if k<61 %点数⼩于60,该⾏应该删掉
l = l-1;
end
end
[m,n] = size(bar_y);
if m<=1 %查看条形码是否有效
fprintf(1,'GameOver!\n');婷婷五月丁香网
return
end
for i=1:m%计算每根条形码的宽度
for j=1:n-1
bar_num(i,j) = bar_y(i,j+1) - bar_y(i,j);
if bar_num(i,j)<0
bar_num(i,j) = 0;
end
end社区工作者吧
end
bar_sum = sum(bar_num)/m;%求每根条形码宽度的平均值k = 0;
for i=1:59%计算59根条形码的总宽度
k = k + bar_sum(i);
end
k = k/95;%计算单位条形码的宽度
for i=1:59%计算每根条形码所占位数
bar_int(i) = round(bar_sum(i)/k);
end
k = 1;
for i=1:59%将条形码转换成⼆进制数
if rem(i,2)
for j=1:bar_int(i)%⿊⾊条⽤1表⽰
bar_01(k) = 1;
k = k+1;
el
for j=1:bar_int(i) %⽩⾊条⽤0表⽰
bar_01(k) = 0;
k = k+1;
end
end
end
疫情一封信if ((bar_01(1)&&~bar_01(2)&&bar_01(3))...%判断起始符是否正确
&&(~bar_01(46)&&bar_01(47)&&~bar_01(48)&&bar_01(49)&&~bar_01(50))... %判断中间分隔符是否正确

本文发布于:2023-07-20 19:27:47,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/1089512.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:条形码   图像   记录   值化
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图