Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions blinkDetect.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

thresh = 0.27

# IMPORTANT: You must download the shape_predictor_68_face_landmarks.dat file from
# https://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2
# and place it in the 'models' folder
modelPath = "models/shape_predictor_68_face_landmarks.dat"
#SINCE MODEL WAS NOT AVAILABLE IN THE REPOSITORY, I DOWNLOADED THE OFFCIAL MODEL FROM THE WEBSITE AND USED THAT
# DOWNLOAD LINK: https://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2
modelPath = r"models\shape_predictor_68_face_landmarks.dat"

sound_path = "alarm.wav"

detector = dlib.get_frontal_face_detector()
Expand Down Expand Up @@ -258,7 +258,7 @@ def end_current_session():
validFrames = 0
dummyFrames = 100

print("Caliberation in Progress!")
print("Calibration in Progress!")
while(validFrames < dummyFrames):
validFrames += 1
t = time.time()
Expand Down Expand Up @@ -353,6 +353,8 @@ def end_current_session():


cv2.imshow("Blink Detection", frame)


vid_writer.write(frame)

k = cv2.waitKey(1)
Expand All @@ -365,6 +367,10 @@ def end_current_session():
elif k == ord('q'):
break

#ADDED FUNCTIONALITY OF TERMINATING ON CLICKING ON 'X'
if cv2.getWindowProperty('Blink Detection', cv2.WND_PROP_VISIBLE) < 1:
break

# print("Time taken", time.time() - t)

except Exception as e:
Expand Down
15 changes: 10 additions & 5 deletions face-try.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import cv2
import sys


# Load Haar cascade
#Absolute path
#cascade_path = '/home/happy/gssoc/driver-drowsiness-detection-system/models/haarcascade_frontalface_default.xml'
Expand Down Expand Up @@ -51,15 +52,19 @@
for (x, y, w, h) in faces:
cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 3)


cv2.imshow('Face Detection', img)

if cv2.waitKey(1) & 0xFF == ord('q'):
print("[INFO] Exiting on user request.")
break

except KeyboardInterrupt:
print("\n[INFO] Exiting on Ctrl+C")

finally:
cap.release()
cv2.destroyAllWindows()
cv2.imshow('Face Detection', img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
#ADDED FUNCTIONALITY OF TERMINATING BY CLICKING ON 'X'
if cv2.getWindowProperty('Face Detection', cv2.WND_PROP_VISIBLE) < 1:
break
cap.release()
cv2.destroyAllWindows()
31 changes: 17 additions & 14 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import tkinter as tk
from tkinter import ttk, messagebox
import subprocess
Expand Down Expand Up @@ -70,6 +71,7 @@ def toggle_theme(root, frame, toggle_btn):

is_dark_mode = not is_dark_mode


def on_quit(root):
if face_proc and face_proc.poll() is None:
face_proc.terminate()
Expand Down Expand Up @@ -97,25 +99,26 @@ def main():

frame = ttk.Frame(root, padding=20, style="Light.TFrame")
frame.pack(expand=True)


frame = Frame(root)
frame.pack(side=TOP, pady=40)

btn_face = ttk.Button(frame, text="Face Detection")
btn_face.config(command=lambda: run_face_detection(btn_face))
btn_face.grid(row=0, column=0, padx=15, pady=15)

btn_blink = ttk.Button(frame, text="Blink Detection")
btn_blink.config(command=lambda: run_blink_detection(btn_blink))
btn_blink.grid(row=0, column=1, padx=15, pady=15)
button1 = Button(frame, text="Face Detection", command=face)
button1.pack(side=LEFT, padx=10, pady=10)

# Toggle button
btn_toggle = ttk.Button(root, text="Switch to Dark Mode")
btn_toggle.config(command=lambda: toggle_theme(root, frame, btn_toggle))
btn_toggle.pack(pady=10)
button2 = Button(frame, text="Blink Detection", command=blink)
button2.pack(side=LEFT, padx=10, pady=10)

# Quit button
btn_quit = ttk.Button(root, text="Quit", command=lambda: on_quit(root))
btn_quit.pack(side=tk.BOTTOM, pady=20)
button3 = Button(root, text="Quit", command=root.destroy)
button3.pack(side=BOTTOM, pady=30)

root.mainloop()






if __name__ == "__main__":
main()