Commit
·
901225d
1
Parent(s):
d26e68c
Upload 2 files
Browse files
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
mixkit-digital-clock-digital-alarm-buzzer-992.wav filter=lfs diff=lfs merge=lfs -text
|
Drowsiness_detection_app.py
ADDED
@@ -0,0 +1,176 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import cv2
|
3 |
+
import time
|
4 |
+
import tensorflow as tf
|
5 |
+
from tensorflow.keras.models import load_model
|
6 |
+
import numpy as np
|
7 |
+
from pygame import mixer
|
8 |
+
|
9 |
+
|
10 |
+
|
11 |
+
from datetime import datetime
|
12 |
+
model = load_model('Drowsiness_model_efficient.h5')
|
13 |
+
|
14 |
+
html_temp= """
|
15 |
+
<div style="background-color:tomato;padding:10px">
|
16 |
+
<h2 style="color:white;text-align:centre;">Drowsiness Detection App </h2>
|
17 |
+
</div>
|
18 |
+
"""
|
19 |
+
st.markdown(html_temp,unsafe_allow_html=True)
|
20 |
+
|
21 |
+
st.markdown(
|
22 |
+
|
23 |
+
"""
|
24 |
+
This app is developed for drowsiness detection. This app will raise an alarm if the person is drowsy.
|
25 |
+
"""
|
26 |
+
)
|
27 |
+
Warning="By selecting the check box you are agree to use our app.\nDon't worry!! We will not save your any data."
|
28 |
+
check=st.checkbox("I agree",help=Warning)
|
29 |
+
if(check):
|
30 |
+
st.write('Great!')
|
31 |
+
btn=st.button("Start")
|
32 |
+
st.write('Press (c) for ending the stream')
|
33 |
+
if btn:
|
34 |
+
|
35 |
+
#multiple cascades: https://github.com/Itseez/opencv/tree/master/data/haarcascades
|
36 |
+
|
37 |
+
#https://github.com/Itseez/opencv/blob/master/data/haarcascades/haarcascade_frontalface_default.xml
|
38 |
+
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
|
39 |
+
|
40 |
+
#https://github.com/Itseez/opencv/blob/master/data/haarcascades/haarcascade_eye.xml
|
41 |
+
eye_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_eye.xml')
|
42 |
+
mixer.init()
|
43 |
+
sound= mixer.Sound(r'mixkit-digital-clock-digital-alarm-buzzer-992.wav')
|
44 |
+
cap = cv2.VideoCapture(0)
|
45 |
+
Score = 0
|
46 |
+
openScore = 0
|
47 |
+
while 1:
|
48 |
+
|
49 |
+
ret, img = cap.read()
|
50 |
+
height,width = img.shape[0:2]
|
51 |
+
frame = img
|
52 |
+
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
53 |
+
faces = face_cascade.detectMultiScale(gray, scaleFactor= 1.3, minNeighbors=2)
|
54 |
+
|
55 |
+
for (x,y,w,h) in faces:
|
56 |
+
cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
|
57 |
+
roi_gray = gray[y:y+h, x:x+w]
|
58 |
+
roi_color = img[y:y+h, x:x+w]
|
59 |
+
eye= img[y:y+h,x:x+w]
|
60 |
+
eye= cv2.resize(eye, (256 ,256))
|
61 |
+
im = tf.constant(eye, dtype = tf.float32)
|
62 |
+
img_array = tf.expand_dims(im, axis = 0)
|
63 |
+
prediction = model.predict(img_array)
|
64 |
+
print(np.argmax(prediction[0]))
|
65 |
+
|
66 |
+
# if eyes are closed
|
67 |
+
if np.argmax(prediction[0])<0.50:
|
68 |
+
cv2.putText(frame,'closed',(10,height-20),fontFace=cv2.FONT_HERSHEY_COMPLEX_SMALL,fontScale=1,color=(255,255,255),
|
69 |
+
thickness=1,lineType=cv2.LINE_AA)
|
70 |
+
cv2.putText(frame,'Score'+str(Score),(100,height-20),fontFace=cv2.FONT_HERSHEY_COMPLEX_SMALL,fontScale=1,color=(255,255,255),
|
71 |
+
thickness=1,lineType=cv2.LINE_AA)
|
72 |
+
Score=Score+1
|
73 |
+
if(Score>25):
|
74 |
+
try:
|
75 |
+
sound.play()
|
76 |
+
|
77 |
+
except:
|
78 |
+
pass
|
79 |
+
|
80 |
+
# if eyes are open
|
81 |
+
elif np.argmax(prediction[0])>0.60:
|
82 |
+
cv2.putText(frame,'open',(10,height-20),fontFace=cv2.FONT_HERSHEY_COMPLEX_SMALL,fontScale=1,color=(255,255,255),
|
83 |
+
thickness=1,lineType=cv2.LINE_AA)
|
84 |
+
cv2.putText(frame,'Score'+str(Score),(100,height-20),fontFace=cv2.FONT_HERSHEY_COMPLEX_SMALL,fontScale=1,color=(255,255,255),
|
85 |
+
thickness=1,lineType=cv2.LINE_AA)
|
86 |
+
Score = Score-1
|
87 |
+
openScore = openScore +1
|
88 |
+
if (Score<0 or openScore >8):
|
89 |
+
Score=0
|
90 |
+
|
91 |
+
|
92 |
+
cv2.imshow('frame',img)
|
93 |
+
|
94 |
+
if cv2.waitKey(33) & 0xFF==ord('c'):
|
95 |
+
break
|
96 |
+
cap.release()
|
97 |
+
cv2.destroyAllWindows()
|
98 |
+
|
99 |
+
st.text("Thanks for using")
|
100 |
+
if st.button("About"):
|
101 |
+
st.text("Created by Surendra Kumar")
|
102 |
+
## footer
|
103 |
+
from htbuilder import HtmlElement, div, ul, li, br, hr, a, p, img, styles, classes, fonts
|
104 |
+
from htbuilder.units import percent, px
|
105 |
+
from htbuilder.funcs import rgba, rgb
|
106 |
+
|
107 |
+
|
108 |
+
def image(src_as_string, **style):
|
109 |
+
return img(src=src_as_string, style=styles(**style))
|
110 |
+
|
111 |
+
|
112 |
+
def link(link, text, **style):
|
113 |
+
return a(_href=link, _target="_blank", style=styles(**style))(text)
|
114 |
+
|
115 |
+
|
116 |
+
def layout(*args):
|
117 |
+
style = """
|
118 |
+
<style>
|
119 |
+
# MainMenu {visibility: hidden;}
|
120 |
+
footer {visibility: hidden;}
|
121 |
+
.stApp { bottom: 105px; }
|
122 |
+
</style>
|
123 |
+
"""
|
124 |
+
|
125 |
+
style_div = styles(
|
126 |
+
position="fixed",
|
127 |
+
left=0,
|
128 |
+
bottom=0,
|
129 |
+
margin=px(0, 0, 0, 0),
|
130 |
+
width=percent(100),
|
131 |
+
color="black",
|
132 |
+
text_align="center",
|
133 |
+
height="auto",
|
134 |
+
opacity=1
|
135 |
+
)
|
136 |
+
|
137 |
+
style_hr = styles(
|
138 |
+
display="block",
|
139 |
+
margin=px(8, 8, "auto", "auto"),
|
140 |
+
border_style="solid",
|
141 |
+
border_width=px(0.5)
|
142 |
+
)
|
143 |
+
|
144 |
+
body = p()
|
145 |
+
foot = div(
|
146 |
+
style=style_div
|
147 |
+
)(
|
148 |
+
hr(
|
149 |
+
style=style_hr
|
150 |
+
),
|
151 |
+
body
|
152 |
+
)
|
153 |
+
st.markdown(style,unsafe_allow_html=True)
|
154 |
+
|
155 |
+
for arg in args:
|
156 |
+
if isinstance(arg, str):
|
157 |
+
body(arg)
|
158 |
+
|
159 |
+
elif isinstance(arg, HtmlElement):
|
160 |
+
body(arg)
|
161 |
+
|
162 |
+
st.markdown(str(foot), unsafe_allow_html=True)
|
163 |
+
|
164 |
+
|
165 |
+
def footer():
|
166 |
+
myargs = [
|
167 |
+
"©️ surendraKumar",
|
168 |
+
br(),
|
169 |
+
link("https://www.linkedin.com/in/surendra-kumar-51802022b", image('https://icons.getbootstrap.com/assets/icons/linkedin.svg') ),
|
170 |
+
br(),
|
171 |
+
link("https://www.instagram.com/im_surendra_dhaka/",image('https://icons.getbootstrap.com/assets/icons/instagram.svg')),
|
172 |
+
]
|
173 |
+
layout(*myargs)
|
174 |
+
|
175 |
+
if __name__ == "__main__":
|
176 |
+
footer()
|
mixkit-digital-clock-digital-alarm-buzzer-992.wav
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:577768b0c1c2dfe5511579d8226d74781d501a723a08f61e8d83842a2b6858c0
|
3 |
+
size 1552734
|