首页 > 源文件素材线报 > 管理系统 >

条形码缺陷检测代码

远浪分享 20477

会员:远浪 分享

条形码缺陷检测代码

条形码缺陷检测:条码中(检测样本的)可能存在的断码、白点、黑点等影响条码外观的瑕疵,检测这些瑕疵,并用红色矩形框将其标出。

部分代码:

clear;
close all;
clc;
%% Binarize the input image
im = imread('images/barcode_7.png');
im_gray = rgb2gray(im); 
level = graythresh(im_gray)
bw = im2bw(im_gray, level);
figure; 
subplot(3, 2, 1); imshow(im_gray); title('original image');
subplot(3, 2, 2); imshow(bw); title('binary result');
%% 基于二值图像bw,将二维码瑕疵区域检测出来 
detect = ~bw;
% subplot(3, 2, 3);imshow(detect); title('detect');
hold on
SE=strel('rectangle',[1 30]);
detect = imdilate(~bw, SE);
f = maxLianTongYu(detect);          %分离第一个二维码
s = maxLianTongYu(detect-f);        %分离第二个二维码
f = f + s;
ROI = imdilate(f, strel('rectangle',[30 30]));
ROI = imerode(ROI, strel('rectangle',[40 40]));  %白色二维码区域
first = f&~bw;                
first = medfilt2(first,[1,5]);         %中值滤波,让过小的缺陷横向特征更明显
% subplot(3, 2, 4);imshow(~first); title('first');
first = imerode(~first, strel('rectangle',[1 35])); %去除竖码条
first = imdilate(first, strel('rectangle',[10 10]));    %让缺陷部分更突出
first = first & ROI;
first = medfilt2(first,[15,2]);         %中值滤波[15,14]
first = medfilt2(first,[18,12]); 
first = imdilate(first, strel('rectangle',[10 10]));


条形码缺陷检测代码

本线报有附件内容,请PC端查看

相关推荐

热门图文

上一篇:开源版中文和越南语贷款源码 贷款平台下载 小额贷款系统 贷款源码运营版

下一篇:连连看游戏页面源码