基于Matlab的缺陷识别检测系统

表面缺陷检测是机器视觉领域中非常重要的一 项研究内容,也称为AOI(Automated optical in— spection)或AsI(Automated surface inspection), 它是利用机器视觉设备获取图像来判断采集图像中 是否存在缺陷的技术.目前,基于机器视觉的表面 缺陷装备已经在各工业领域广泛替代人工肉眼检 测,包括3C、汽车、家电、机械制造、半导体及电子、 化工、医药、航空航天、轻工等行业.传统的基于机 器视觉的表面缺陷检测方法,往往采用常规图像处 理算法或人工设计特征加分类器方式.

基于Matlab的缺陷识别检测系统

一、算法描述

近年来,随着以卷积神经网络fConv01utional neural network,CNN)为代表的深度学习模型在 诸多计算机视觉(Computer vjsion,CV)领域成功 应用,例如人脸识别、行人重识别、场景文字检测、 目标跟踪和自动驾驶等,不少基于深度学习的缺陷 检测方法也广泛应用在各种工业场景中,甚至国内 外一些公司开发出多种基于深度学习的商用工业表 面缺陷检测软件,如表1所示.全球传统工业视觉 及其部件的市场规模在2025年将达到192亿美元【“, 其中中国占比约为30%,并保持14%的年度平均增 长率,这一领域正在逐步被新一代基于深度学习的 工业视觉技术替代.同时我国在《中国制造2025》 白皮书中提出“推广采用先进成型和加工方法、在 线检测装置、智能化生产和物流系统及检测设备等, 使重点实物产品的性能稳定性、质量可靠性、环境 适应性、使用寿命等指标达到国际同类产品先进水 平”。

基于Matlab的缺陷识别检测系统

近年来,基于深度学习的表面缺陷检测技术已广泛应用于各种工业场景。本文梳理了近年来基于深度学习的表面缺陷检测方法,根据数据标签的不同将其分为三类:全监督学习模型方法、无监督学习模型方法和其他方法。细分分类对比分析,总结出每种方法的优缺点和应用场景。

在金属机械零件表面缺陷检测过程中,需要引入级联 分类器,对全部连接层中的输出特征进行分类处理,使其 能够获取更加准确的分类结果。为了全面提取全连接层的 特征,采用卷积神经网络的梯度直方图和局部二值模式提 取输出特征,同时对多个不同级联分类器依次进行训练, 将得到的分类结果进行决策融合,根据决策融合结果实现 零件表面缺陷检测。 方向梯度直方图在细微变形的特征下具有良好的不 变特性,但是方向梯度直方图描述局部特征的能力存在缺 陷,同时对噪声十分敏感。局部二值模式具有较好的局部 表达能力,所以方向梯度直方图和局部二值模式具有比较 好的互补性。 当通过卷积神经网络提取原始金属机械零件图像的特 征后,将提取到的特征进行统计,同时将其放入到全连接 层中。全面利用HOG和LBP的互补特征,进一步提取HOG 的输出特征。采用以上方式提取到的特征值具有比较强的 鲁棒特性。

二、代码实现

function varargout = main(varargin)
% MAIN MATLAB code for main.fig
%      MAIN, by itself, creates a new MAIN or raises the existing
%      singleton*.
%
%      H = MAIN returns the handle to a new MAIN or the handle to
%      the existing singleton*.
%
%      MAIN('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in MAIN.M with the given input arguments.
%
%      MAIN('Property','Value',...) creates a new MAIN or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before main_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to main_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 main
 
% Last Modified by GUIDE v2.5 18-Apr-2022 10:33:59
 
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @main_OpeningFcn, ...
                   'gui_OutputFcn',  @main_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 main is made visible.
function main_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 main (see VARARGIN)
 
% Choose default command line output for main
handles.output = hObject;
 
set(handles.radiobutton1,'value',0);
set(handles.radiobutton2,'value',0);
 
axes(handles.axes1); %指定需要清空的坐标轴
cla reset;
box on;
set(handles.axes1,'xtick',[]);
set(handles.axes1,'ytick',[]);
axes(handles.axes2); %指定需要清空的坐标轴
cla reset;
box on; %在坐标轴四周加上边框
set(handles.axes2,'xtick',[]);
set(handles.axes2,'ytick',[]);
axes(handles.axes3); %指定需要清空的坐标轴
cla reset;
box on; %在坐标轴四周加上边框
set(handles.axes3,'xtick',[]);
set(handles.axes3,'ytick',[]);
set(handles.edit1,'string','');
set(handles.edit2,'string','');
set(handles.edit3,'string','');
set(handles.edit4,'string','');
 
% Update handles structure
guidata(hObject, handles);
 
% UIWAIT makes main wait for user response (see UIRESUME)
% uiwait(handles.figure1);
 
 
% --- Outputs from this function are returned to the command line.
function varargout = main_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)
clc;
clear;
output=VOCxml_to_matlab_main();
save dataSet output;
 
% --- 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)
global inputSize;
data=load('dataSet');
data=data.output;
 
% 数据存储在一个包含三列的表中,其中第一列包含图像文件路径,第二列包含车辆边界框,
% 第三列对应的类别。
% 将数据集分成训练集、验证集和测试集。选择 60% 的数据用于训练,10% 用于验证,
% 其余用于测试经过训练的检测器
 
shuffledIndices = randperm(height(data));
idx = floor(0.6 * height(data));
 
trainingIdx = 1:idx;
trainingDataTbl = data(shuffledIndices(trainingIdx),:);
 
validationIdx = idx+1 : idx + 1 + floor(0.1 * length(shuffledIndices) );
validationDataTbl = data(shuffledIndices(validationIdx),:);
 
testIdx = validationIdx(end)+1 : length(shuffledIndices);
testDataTbl = data(shuffledIndices(testIdx),:);
 
% 使用 imageDatastore 和 boxLabelDatastore 创建数据存储,
% 以便在训练和评估期间加载图像和标签数据
imdsTrain = imageDatastore(trainingDataTbl{:,'imageFilename'});
bldsTrain = boxLabelDatastore(trainingDataTbl(:,2:end));
 
 
imdsValidation = imageDatastore(validationDataTbl{:,'imageFilename'});
bldsValidation = boxLabelDatastore(validationDataTbl(:,2:end));
 
imdsTest = imageDatastore(testDataTbl{:,'imageFilename'});
bldsTest = boxLabelDatastore(testDataTbl(:,2:end));
 
%组合图像和边界框标签数据存储
trainingData = combine(imdsTrain,bldsTrain);
validationData = combine(imdsValidation,bldsValidation);
testData = combine(imdsTest,bldsTest);
 
%显示其中一个训练图像和边界框标签
data = read(trainingData);
I = data{1};
bbox = data{2};
annotatedImage = insertShape(I,'Rectangle',bbox);
annotatedImage = imresize(annotatedImage,2);
figure
imshow(annotatedImage)
 
%是否需要训练
doTraining=true;
 
end

基于Matlab的缺陷识别检测系统

参考

【1】黄凤荣,李杨.基于Faster RCNN的零件表面缺陷检测算法.

【2】卢颖颖,孙育.基于机器视觉的电镀件表面缺陷检测系统.

详情资料请扣扣:1341703358。本文探讨了表面缺陷检测中三个关键问题, 介绍了工业表面缺陷常用数据集.最后,对表面缺陷检测的未来发展趋势进行了展望.

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
乘风的头像乘风管理团队
上一篇 2022年4月20日 下午7:18
下一篇 2022年4月24日 上午11:37

相关推荐