【疲劳检测】基于形态学实现疲劳检测matlab源码

1 基于形态学实现疲劳检测

1.1 疲劳概述

    疲劳是一种长时间或反复受到刺激后而产生的复杂的生理和心理现象 ,是与日常健康功能相联系的绝大多数急性和慢性病的症状人们通常所说的疲劳大都是指生理疲劳。生理疲劳即肉体疲劳,它是一个复杂的现象,受到心理生理因素的影响。目前检测到的生理生化指标与生理疲劳之间的波动关系相对较为稳定,指向较为明确,比较容易检测,人们可以根据情况及时休息,加以调整。随着时代的发展,很多行业的从业人员,不再从事纯粹的体力劳动,比如客车驾驶员,IT 从业人员,运动员,飞行员,军人等。当面对单调枯燥,工作压力大或责任重大的工作,他们更容易产生情绪低落,心烦意乱等负性情绪。据此,人们提出了心理疲劳这一概念。并且,经研究表明,心理疲劳是一个渐进和积累的过程,它与惰性的增加,警觉性和工作效率的降低以及心理障碍有紧密联系,一般表现为感觉疲倦,情感压抑和活力衰退。北京体育大学的林岭认为,心理疲劳是心理和生理过程交融的过程,这种生理,心理的交互作用将导致复杂的内部神经生理和外部行为、情绪、动机等疲劳现象的综合变化。同时,心理疲劳受到许多因素的影响,如营养,身体健康状况,环境,机体活力和休养调整期等。如今,随着大众对心理健康问题越来越关注,心理疲劳的检测也随之受到更多的重视。

1.2 模板匹配算法

【疲劳检测】基于形态学实现疲劳检测matlab源码

2 部分代码

function varargout = GUI(varargin)
% GUI MATLAB code for GUI.fig
%     GUI, by itself, creates a new GUI or raises the existing
%     singleton*.
%
%     H = GUI returns the handle to a new GUI or the handle to
%     the existing singleton*.
%
%     GUI('CALLBACK',hObject,eventData,handles,...) calls the local
%     function named CALLBACK in GUI.M with the given input arguments.
%
%     GUI('Property','Value',...) creates a new GUI or raises the
%     existing singleton*. Starting from the left, property value pairs are
%     applied to the GUI before GUI_OpeningFcn gets called. An
%     unrecognized property name or invalid value makes property application
%     stop. All inputs are passed to GUI_OpeningFcn via varargin.
%
%     *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
%     instance to run (singleton)".  
%

gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                  'gui_Singleton',  gui_Singleton, ... 
                  'gui_OpeningFcn', @GUI_OpeningFcn, ...
                  'gui_OutputFcn',  @GUI_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 GUI is made visible.
function GUI_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 GUI (see VARARGIN)

% Choose default command line output for GUI
handles.output = hObject;


handles.output = hObject;
ha=axes('units','normalized','pos',[0 0 1 1]);
uistack(ha,'down');
ii=imread('背景图.jpg'); 
image(ii);
colormap gray
set(ha,'handlevisibility','off','visible','off');
% Update handles structure
guidata(hObject, handles);

% UIWAIT makes GUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = GUI_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)


% 显示figure标记
flag = 1;
% 获取图片库文件列表
files = ls('video_images/*.jpg');
%N = size(files, 1);
N=15;

kk=0
for i = 1 : N
   file = fullfile(pwd, 'video_images', files(i, :));
   Img = imread(file);
   % 图像预处理
  [Im1, rectValide] = GetValideImage(Img, 0);%自定义的函数
   figure(99)
   imshow(Im1)
   imwrite(Im1,'ceshi.jpg')
  [m n]=size(Im1)
 
   % 人脸区域定位
  [Im2, bw, rectFace] = GetFaceAreaImg(Im1, 0);
   % 人眼区域定位
  [Im3, rectEye] = GetEyeAreaImg(Im2, 0);
   % 人眼精确定位
  [Im4, bwf, rect, nv] = GetEyeAccurateImg(Im3, 0);
   % 统计特征信息
   Nv(i).file = file;%%帧图像名称路径
   
   Nv(i).nv = nv;%921
  
   Nv(i).rectEye = rectEye;%8 31   163 40
   
   Nv(i).rectEyes = rect;%1x4   1x4
   
   Nv(i).rectFace = rectFace;%90.5000   153.0000 198   192
   
   Nv(i).rectValide = rectValide;%301 1   359   600
   

   imshow(Img, []);%%%%原图
   hold on;
   % 人脸区域
   r_face = [Nv(i).rectFace(1)+Nv(i).rectValide(1) Nv(i).rectFace(2)+Nv(i).rectValide(2) Nv(i).rectFace(3:4)];
   % 人眼区域
   r_eye = [Nv(i).rectEye(1)+r_face(1) Nv(i).rectEye(2)+r_face(2) Nv(i).rectEye(3:4)];
   % 人眼精确区域
   r_eyes1 = [Nv(i).rectEyes{1}(1)+r_eye(1) Nv(i).rectEyes{1}(2)+r_eye(2) Nv(i).rectEyes{1}(3:4)];
   r_eyes2 = [Nv(i).rectEyes{2}(1)+r_eye(1) Nv(i).rectEyes{2}(2)+r_eye(2) Nv(i).rectEyes{2}(3:4)];
   rectangle('Position', r_face, 'EdgeColor', 'y', 'LineWidth', 2);
   rectangle('Position', r_eyes1, 'EdgeColor', 'r', 'LineWidth', 1);
   rectangle('Position', r_eyes2, 'EdgeColor', 'r', 'LineWidth', 1);
   title(Nv(i).status);
  
   hold off;
   pause(6);%间隔时间
end
f1=(N-kk)/N
if f1>0.12
   fprintf('疲劳')
   set(handles.edit3,'string','检测结果为:疲劳')
    [filex,fs]=audioread('警报.wav');
    sound(filex,fs);
else
   fprintf('非疲劳')
   set(handles.edit3,'string','检测结果为:非疲劳')
end

% 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)


% --- Executes on selection change in listbox1.
function listbox1_Callback(hObject, eventdata, handles)
% hObject   handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles   structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns listbox1 contents as cell array
%       contents{get(hObject,'Value')} returns selected item from listbox1


% --- Executes during object creation, after setting all properties.
function listbox1_CreateFcn(hObject, eventdata, handles)
% hObject   handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles   empty - handles not created until after all CreateFcns called

% Hint: listbox controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
   set(hObject,'BackgroundColor','white');
end



function edit1_Callback(hObject, eventdata, handles)
% hObject   handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles   structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit1 as text
%       str2double(get(hObject,'String')) returns contents of edit1 as a double


% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject   handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles   empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
   set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in listbox2.
function listbox2_Callback(hObject, eventdata, handles)
% hObject   handle to listbox2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles   structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns listbox2 contents as cell array
%       contents{get(hObject,'Value')} returns selected item from listbox2


% --- Executes during object creation, after setting all properties.
function listbox2_CreateFcn(hObject, eventdata, handles)
% hObject   handle to listbox2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles   empty - handles not created until after all CreateFcns called

% Hint: listbox controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
   set(hObject,'BackgroundColor','white');
end



function edit2_Callback(hObject, eventdata, handles)
% hObject   handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles   structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit2 as text
%       str2double(get(hObject,'String')) returns contents of edit2 as a double


% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject   handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles   empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
   set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in listbox3.
function listbox3_Callback(hObject, eventdata, handles)
% hObject   handle to listbox3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles   structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns listbox3 contents as cell array
%       contents{get(hObject,'Value')} returns selected item from listbox3


% --- Executes during object creation, after setting all properties.
function listbox3_CreateFcn(hObject, eventdata, handles)
% hObject   handle to listbox3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles   empty - handles not created until after all CreateFcns called

% Hint: listbox controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
   set(hObject,'BackgroundColor','white');
end


% --- 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)



function edit3_Callback(hObject, eventdata, handles)
% hObject   handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles   structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit3 as text
%       str2double(get(hObject,'String')) returns contents of edit3 as a double


% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject   handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles   empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
   set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
%% 将视频逐帧保存为jpg图片

obj = VideoReader(uigetfile('*.avi','选择视频'));%输入视频位置
setappdata(0,'obj',obj);%设置全局变量
Show_Frames=read(obj,1);%显示第一帧作为封面
axes(handles.axes1);
imshow(Show_Frames);
set(handles.listbox1,'String','分帧开始...');

prompt={'输入图片名是几位数:'};
defans={'2'};%默认两位数
p=inputdlg(prompt,'输入位数',1,defans);
numzeros=str2num(p{1});
  nz = strcat('%0',num2str(numzeros),'d');

numFrames = obj.NumberOfFrames;% 帧的总数
for k = 1 :5% 读取前15帧 numFrames
frame = read(obj,k);%读取第几帧
id=sprintf(nz,k);
imwrite(frame,strcat('video_images/',id,'.jpg'),'jpg');% 保存帧
end
set(handles.listbox1,'String','分帧结束');


% hObject   handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles   structure with handles and user data (see GUIDATA)

【疲劳检测】基于形态学实现疲劳检测matlab源码

3 仿真结果

【疲劳检测】基于形态学实现疲劳检测matlab源码

【疲劳检测】基于形态学实现疲劳检测matlab源码

【疲劳检测】基于形态学实现疲劳检测matlab源码

【疲劳检测】基于形态学实现疲劳检测matlab源码

4 参考文献

[1]*春, 何仁, 林谋有,等. 驾驶员疲劳检测技术的研究现状及发展趋势[J]. 农机化研究, 2006(05):197-199.

【疲劳检测】基于形态学实现疲劳检测matlab源码

 

上一篇:【人脸识别】基于 Gabor+SVM和PCA+SVM实现人脸识别matlab源码含 GUI


下一篇:【滤波器】基于matlab GUI高通+低通+带通+带阻FIR滤波器设计【含Matlab源码 1346期】