Driver Sleep Alert System - Matlab

Durum
Üzgünüz bu konu cevaplar için kapatılmıştır...
Üye
Katılım
5 Şub 2019
Mesajlar
20
Tepki puanı
10
Yaş
36
7 HİZMET YILI
MATLAB:
function varargout = Driver_Sleep_Alert_System(varargin)
% DRIVER_SLEEP_ALERT_SYSTEM MATLAB code for Driver_Sleep_Alert_System.fig
%      DRIVER_SLEEP_ALERT_SYSTEM, by itself, creates a new DRIVER_SLEEP_ALERT_SYSTEM or raises the existing
%      singleton*.
%
%      H = DRIVER_SLEEP_ALERT_SYSTEM returns the handle to a new DRIVER_SLEEP_ALERT_SYSTEM or the handle to
%      the existing singleton*.
%
%      DRIVER_SLEEP_ALERT_SYSTEM('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in DRIVER_SLEEP_ALERT_SYSTEM.M with the given input arguments.
%
%      DRIVER_SLEEP_ALERT_SYSTEM('Property','Value',...) creates a new DRIVER_SLEEP_ALERT_SYSTEM or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before Driver_Sleep_Alert_System_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to Driver_Sleep_Alert_System_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 Driver_Sleep_Alert_System

% Last Modified by GUIDE v2.5 01-Feb-2018 10:41:20

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
    'gui_Singleton',  gui_Singleton, ...
    'gui_OpeningFcn', @Driver_Sleep_Alert_System_OpeningFcn, ...
    'gui_OutputFcn',  @Driver_Sleep_Alert_System_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 Driver_Sleep_Alert_System is made visible.
function Driver_Sleep_Alert_System_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 Driver_Sleep_Alert_System (see VARARGIN)

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

set(handles.Start_System,'Enable','off');
warning off all;
clc;

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = Driver_Sleep_Alert_System_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 Start_Camera_btn.
function Start_Camera_btn_Callback(hObject, eventdata, handles)
% hObject    handle to Start_Camera_btn (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% add ./find_face_landmarks/bin to SYSTEM PATH using Environment variables

set(handles.Start_System,'Enable','on');

addr = genpath('.');
addpath(addr);


imaqreset

vid = videoinput('winvideo', 1, 'MJPG_640x480');
src = getselectedsource(vid);
vid.FramesPerTrigger = Inf;

start(vid);

axes(handles.axes1);
h1 = image(zeros(480,640));         % create image object
axis ij;            % flip the image
preview(vid,h1)

handles.vid = vid;
guidata(hObject,handles);







% --- Executes on button press in Start_System.
function Start_System_Callback(hObject, eventdata, handles)
% hObject    handle to Start_System (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

set(handles.Start_System,'Enable','off');

global stopflag;
global stopAlarmflag;
stopflag = 0;
stopAlarmflag = 0;
COUNTER_1 = 0;
COUNTER_2 = 0;
EYE_AR_CONSEC_FRAMES = 5;
FACE_CONSEC_FRAMES = 5;

modelFile = './shape_predictor_68_face_landmarks.dat';

while stopflag == 0
    
    stopflag = get(handles.Stop_System,'Value');
    
    vid = handles.vid;
    I = getsnapshot(vid);
    
    frame = find_face_landmarks(modelFile, I);
    
    if ~isempty(frame.faces)
        COUNTER_2 = 0;
        
        landmark_coordinates = frame.faces.landmarks;
        EAR = Eye_Aspect_Ratio(frame);
        [MAR, H] = Mouth_Aspect_Ratio(frame);
        
        fprintf('EAR: %f, H: %d\n', EAR,H)
        
        
        axes(handles.axes2);
        imshow(I);
        hold on;
        show_landmarks_frame(frame);
        drawnow
        
        if H > 10 || EAR < 1
            COUNTER_1 = COUNTER_1 + 1;
            if COUNTER_1 >= EYE_AR_CONSEC_FRAMES
%                 while stopAlarmflag == 0
%                     stopAlarmflag = get(handles.StopAlarm,'Value');
                    beep2
%                 end
            end
        else
            COUNTER_1 = 0;
        end
    else
        COUNTER_2 = COUNTER_2 + 1;
        if COUNTER_2 >= FACE_CONSEC_FRAMES
%             while stopAlarmflag == 0
%                 stopAlarmflag = get(handles.StopAlarm,'Value');
                beep2
%             end
        end
    end
    
end
imaqreset


% --- Executes on button press in Exit_btn.
function Exit_btn_Callback(hObject, eventdata, handles)
% hObject    handle to Exit_btn (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

imaqreset
close all;


% --- Executes on button press in Stop_System.
function Stop_System_Callback(hObject, eventdata, handles)
% hObject    handle to Stop_System (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of Stop_System

get(hObject,'Value')


% --- Executes on button press in StopAlarm.
function StopAlarm_Callback(hObject, eventdata, handles)
% hObject    handle to StopAlarm (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of StopAlarm
get(hObject,'Value')
 
T H O R
Süper Üye
Katılım
12 Haz 2020
Mesajlar
644
Çözümler
2
Tepki puanı
110
Ödüller
5
Yaş
26
5 HİZMET YILI
son zamanlarda kendini aştın aynen devam et takipteyiz <3
 
Seçkin Üye
Katılım
20 Haz 2020
Mesajlar
298
Çözümler
2
Tepki puanı
3
Ödüller
3
Sosyal
5 HİZMET YILI
A Matlab code is written to moniter the status of a person and sound an alarm in case of drowsiness. i ... Unzip and place the 'Sleep' folder in the path of Matlab.
 
Durum
Üzgünüz bu konu cevaplar için kapatılmıştır...
Üst