File Exchange

image thumbnail

Drowsiness Detection using a Binary SVM Classifier

version 1.0.0.0 (189 KB) by Manu BN
A Matlab code for Drowsiness Detection

53 Downloads

Updated 29 Mar 2017

View License

A Matlab code is written to moniter the status of a person and sound an alarm in case of drowsiness. i have already trained the SVM classifier with Fatigue and Non Fatigue samples.
How to run??
1. Unzip and place the 'Sleep' folder in the path of Matlab.
2. Turn on your webcam, go to command window and type 'imaqtool' to find the supported adaptors.
3. Open main.m and go to line no. 17 and change the adaptor name to the supported one.
(Usually 'winvideo',1 is supported in all windows versions).
4. Now run main.m
5. Place yourself at a distance such that your face is visible in the window
6. Non Fatigue Status: The default status, appears when your eyes are wide open and mouth is closed
7. Fatigue Status: When eyes are closed and mouth is opened for several seconds, the alarm sounds a beep.
8. Make sure the room is well lit
Note: The model is not trained to work perfectly under dark or very low dim light conditions, I will upload a much better code once I get better results with an efficient set of features.
Cite the following if you are using my work:
[1] Manu, B. N. "Facial features monitoring for real time drowsiness detection." Innovations in Information Technology (IIT), 2016 12th International Conference on. IEEE, 2016.

IEEE Paper Download link: https://www.researchgate.net/publication/315685957_Facial_Features_Monitoring_for_Real_Time_Drowsiness_Detection

PPT Download link: https://www.researchgate.net/publication/315686000_Facial_Features_Monitoring_for_Real_Time_Drowsiness_Detection_PPT

Suggestions and comments are always welcome,

Thanks in advance,

Manu B.N

Cite As

Manu BN (2019). Drowsiness Detection using a Binary SVM Classifier (https://www.mathworks.com/matlabcentral/fileexchange/55152-drowsiness-detection-using-a-binary-svm-classifier), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (46)

esu tes

Can you send me the code esutes27@gmail.com

please send the code to priyankanair983@gmail.com

rasna p

can you send me the source code to rasnaravi205@gmail.com

micheal t

please send the code to michealtraj@gmail.com

In output it is always showing 'fatigue' after 10 seconds. Though my eye is open it is showing eye as closed. What is the reason?
I tried in both matlab 2014a and 2016a.
Can you send me the solution for this?
my mail id is mahaboob111410@gmail.com

Thank you. This code for live video works for me. Is it possible to get similar code for pretaken video in dim light or night mode light. Kindly help with the upgraded coding.

Plz snd me the code

Tushar Puri

Can u plz send code to tusharpuri54@gmail.com

Meghna Megi

Can u plz send code to meghnak71@gmail.com

please send this code to csk14at1a04@gmail.com

Francesco

I have a technical problem: I am not able to extract correctly the files form .zipx (even if renamed in .zip). All the .m file present an error while the DB can be extracted....
Is it possible to have a new .zip? From an hosting server link maybe..

Thanks in advance for you attention and collaboration.

Bests,
Fra

hi
can you send data base name ?

Kudos Manu!!!

could you please tel me how to get the output and how many images should be given

Sir how can I modify this code to include a webcam instead of using the default laptop camera

Yash Maurya

Can someone please give me this source code here, , I am new to matlab and dont know much functionalities, like how to place sleep in matlab path folder. Please help. Thankyou

Sanjib Das

Rename sleep.zipx to sleep.zip.
It will work

Can you please send me the source code (feranto31@hotmail.com). When i unzip the "Sleep.zip", i have Sleep.zipx and i dont know what to do with this file.

Mahesh Pala

not getting output.. its showing error at
faceDetector = vision.CascadeObjectDetector;

anupama a

sir can u giv a code for automatic region of interest selection ?is thre any database to get echocardiographic videos in which there is a tumor or thrombus in heart?

anupama a

sir can u giv a code for automatic region of interest selection

Zaid Zaid

Undefined variable "vision" or class "vision.ShapeInserter

Manu BN

For skin segmentation.
Thanks for the rating.

Hello, first congratulate you on your work. Could you tell me what the skin_seg2.m function is? Thanks and best regards

tian guo

nice work, Plz attach the dataset, if possible. Thanks very much.

Manu BN

I will add a detailed documents regarding training and databases also once my paper is published.

According to documentation,
6. Non Fatigue Status: The default status, appears when your eyes are wide open and mouth is closed
7. Fatigue Status: When eyes are closed and mouth is opened for several seconds, the alarm sounds a beep.

But at my side, it is not even running properly why its is giving output eyes not detected again and again secondly, where is SVM training file and DATABASE?

fathima .k

I cant find the file provided here.Can you please send me the source code.
fathi.kaf@gmail.com

Mk khan

??? Undefined function or variable 'vision'.

Error in ==> main at 35
faceDetector = vision.CascadeObjectDetector;

showing ths plus video output window not opening and cam light is ON

Manu BN

@rafik,@Mugilan: Why cant you download the code provided here ??

rafik rafik

can you please send me the source code
freedom-king2016@hotmail.com

can you please send me the source code, mugilan930311@hotmail.com

Manu BN

@Faizal, Tibarius: I'm coming up with a document on that so plz wait as i'm super busy.
@ pawan: It's all Viola Jones. I wonder what Nose Detection is doing in your code??? How does it help decide the drowsiness???

faizal

Hi Mr Manu, thanks for your code. It work great.

For further use of your code, can u guide us how to train our own SVM?

Thank you.

pawan gupta

Hi,can anybody tell me about the algorithm which is used in the following code? like viola jones,template matching etc.

it would be greatly appericiated if u could help me.
thank you!!!

clc
clear all;
close all;

% initialize webcam (read instructions if required 'README_TO_SET_YOUR_CAMERA.m')

vobj=videoinput('winvideo',1,'YUY2_640x480','ReturnedColorSpace','rgb');
figure('Name','My Custom Preview Window');
uicontrol('string','close','callback','close(gcf)');

% create an image object for previewing

vidRes=get(vobj,'VideoResolution');
nBands=get(vobj,'NumberOfBands');
hImage=image(zeros(vidRes(2),vidRes(1),nBands));
preview(vobj,hImage);

%pause
% coordinates to draw lines

rs=vidRes(2);
cs=vidRes(1);
C1=floor(cs/6);
C2=floor(267*cs/320);

C3=floor(0);
C4=floor(cs);

R1=floor(rs/4);
R2=floor(rs/2);
R3=floor(3*rs/4);
R4=floor(rs);

x1=[C1 C1];
x2=[C2 C2];
x3=[C3 C3];
x4=[C4 C4];

x5=[C3 C4];

y1=[0 rs];
y2=[R1 R1];
y3=[R2 R2];
y4=[R3 R3];
y5=[R4 R4];

%draw lines

line(x1,y1,'color','r','LineWidth',2)
line(x2,y1,'color','r','LineWidth',2)

%line(x3,y1,'color','g','LineWidth',2)
%line(x4,y1,'color','g','LineWidth',2)

line(x5,y2,'color','g','LineWidth',2)
line(x5,y3,'color','g','LineWidth',2)
line(x5,y4,'color','g','LineWidth',2)

%line(x5,y5,'color','w','LineWidth',2)

% write text

text1=text(19*cs/96,rs/8,'FOREHEAD REGION','color','r');
text2=text(19*cs/96,3*rs/8,'EYE REGION','color','r');
text3=text(19*cs/96,5*rs/8,'NOSE REGION','color','r');
text4=text(19*cs/96,7*rs/8,'MOUTH REGION','color','r');
% initialize flags

FlagForHead=0;
FlagEyes=0;
FlagNose=0;
FlagMouth=0;

cnt=0;

% initialize vision toolbox

shape=vision.ShapeInserter('BorderColor','Custom','CustomBorderColor',[255 255 0]);
EyeDetector1=vision.CascadeObjectDetector('EyePairSmall');
NoseDetector=vision.CascadeObjectDetector('Nose');
MouthDetector1=vision.CascadeObjectDetector('Mouth');

%% press any key while you are ready

for i=1:50 % for 200 frames, increse/decrese if required
I2=getsnapshot(vobj);
pause(0.5)
FirstSeg=imcrop(I2,[C1 0 C2-C1 R1]);
% figure(2),subplt(1,2,1);imshow(FirstSeg);

BlackDetect=(FirstSeg(:,:,1)<70)&(FirstSeg(:,:,2)<70)&(FirstSeg(:,:,3)<70);
BW1=imfill(BlackDetect,'holes');
BW2=bwareaopen(BW1,2000);
%subplot(1,2,2),imshow(BW2);
[Matl Nr]=bwlabel(BW2);
if Nr~=0
FlagForHead=1;
else
FlagForHead=0;
end
SecondSegment=imcrop(I2,[C1 R1 C2-C1 R2-R1]);
figure(3),subplot(1,2,1),imshow(SecondSegment);
bbox_eye1=step(EyeDetector1,SecondSegment);
I_Eye=step(shape,SecondSegment,int32(bbox_eye1));
if isempty(bbox_eye1)~=1
FlagEyes=1;
EyeRegion=imcrop(SecondSegment,[bbox_eye1(1,1),bbox_eye1(1,2),bbox_eye1(1,3),bbox_eye1(1,4)]);
subplot(3,2,1),imshow(I_Eye),title('EYE INPUT');
subplot(1,2,2),imshow(EyeRegion),title('EYE REGION');
else
FlagEyes=0;
end;
ThirdSegment=imcrop(I2,[C1 R2 C2-C1 R3-R2]);
% figure(4),subplot(1,2,1),imshow(ThirdSegment);
bbox_Nose1=step(NoseDetector,ThirdSegment);
I_Nose=step(shape,ThirdSegment,int32(bbox_Nose1));
if isempty(bbox_Nose1)~=1
FlagNose=1;
%
NoseRegion=imcrop(ThirdSegment,[bbox_Nose1(1,1),bbox_Nose1(1,2),bbox_Nose1(1,3),bbox_Nose1(1,4)]);
%subplot(3,2,5),imshow(I_Nose),title('Nose INPUT');
%subplot(1,2,2),imshow(NoseRegion),title('Nose REGION');
else
FlagNose=0;
end;
FourthSegment=imcrop(I2,[C1 R3 C2-C1 R4-R3]);
%figure(5),subplot(1,2,1),imshow(FourthSegment);
bbox_Mouth1=step(MouthDetector1,FourthSegment);
I_Mouth=step(shape,FourthSegment,int32(bbox_Mouth1));
if isempty(bbox_Mouth1)~=1
FlagMouth=1;
%
MouthRegion=imcrop(FourthSegment,[bbox_Mouth1(1,1),bbox_Mouth1(1,2),bbox_Mouth1(1,3),bbox_Mouth1(1,4)]);
% subplot(3,2,3),imshow(I_Mouth),title('MOUTH INPUT');
% subplot(1,2,2),imshow(MouthRegion),title('MOUTH REGION');
else
FlagMouth=0;
end;
if ((FlagForHead==1)&&(FlagEyes==1)&&(FlagNose==1)&&(FlagMouth==1))
disp('Normal Condition')
cnt=0;
else
disp('possible drowsiness detection')
cnt=cnt+1;
end
if cnt>5
cnt=0;
disp('drowsiness confirmed')
end
end


Tiberius

I would like to make a training set and a test set with my own images and to train the SVM classifier, but I don't know how to implement this.

Manu BN

Sure, Plz be a little more specific

Tiberius

Hi, can you please help with a tutorial or documents on how to train myself the SVM? Thank you

I

split range

Works like a charm!!!

Matthew

dependencies(?)

Perfectly working code...............

Updates

1.0.0.0

Updated with links to paper & PPT

1.0.0.0

Citations are added

1.0.0.0

IEEE paper download link & PPT download links are added

MATLAB Release Compatibility
Created with R2013a
Compatible with any release
Platform Compatibility
Windows macOS Linux