matlab一维条形码码字识别程序文件.doc

  1. 1、本文档共10页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
. . . .......... close 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; else 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; else T=(T0+T1)/2; end end count T K=find(JT); 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)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:n if ka_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:n if ka_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

文档评论(0)

smdh + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档