SlideShare a Scribd company logo
1 of 7
Download to read offline
You are task to add a yawning detection to the programme below;
import numpy as np
from pygame import mixer
import time
import cv2
from tkinter import *
import tkinter.messagebox
import mysql.connector
from datetime import datetime
root = Tk()
root.geometry('500x570')
frame = Frame(root, relief=RIDGE, borderwidth=2)
frame.pack(fill=BOTH, expand=1)
root.title('Drive Main')
frame.config(background='#74B0D6')
label = Label(frame, text="Drive Care", bg='#74B0D6', font='Garcedo 25 bold')
label.pack(side=TOP)
filename = PhotoImage(file="picco.png")
background_label = Label(frame, image=filename)
background_label.pack(side=TOP)
from mysql.connector import Error
def connect():
""" Connect to MySQL database """
conn = None
try:
conn = mysql.connector.connect(host='localhost',
database='drive_main',
user='root',
password='')
mySql_insert_query = """INSERT INTO tbl_drivers(id, name, event_time)
VALUES (%s, %s, %s) """
cursor = conn.cursor()
current_Date = datetime.now()
# convert date in the format you want
formatted_date = current_Date.strftime('%Y-%m-%d %H:%M:%S')
insert_tuple = (5, 'meleda ulett', current_Date)
result = cursor.execute(mySql_insert_query, insert_tuple)
conn.commit()
print("Date Record inserted successfully")
if conn.is_connected():
print('Connected to MySQL database')
except Error as e:
print(e)
except mysql.connector.Error as error:
conn.rollback()
print("Failed to insert into MySQL table {}".format(error))
finally:
if conn is not None and conn.is_connected():
conn.close()
connect()
def hel_doc():
help(cv2)
def Contri():
tkinter.messagebox.showinfo("Contributors", "n1.Romairo Reidn2. Kayla-Marie Sooman n3.
Bradly Walcott n4. Lee Hinds n")
def anotherWin():
tkinter.messagebox.showinfo("About",
'Drive Care version 01.1n Made Usingn-OpenCVnpn-Tkintern In Python
3')
menu = Menu(root)
root.config(menu=menu)
subm1 = Menu(menu)
menu.add_cascade(label="Tools", menu=subm1)
subm1.add_command(label="Open CV Docs", command=hel_doc)
subm2 = Menu(menu)
menu.add_cascade(label="About", menu=subm2)
subm2.add_command(label="Driver Cam", command=anotherWin)
subm2.add_command(label="Contributors", command=Contri)
def exitt():
exit()
def web():
capture = cv2.VideoCapture(0)
while True:
ret, frame = capture.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow('frame', frame)
if cv2.waitKey(1) & 0xFF == ord('e'):
break
capture.release()
cv2.destroyAllWindows()
def webrec():
capture = cv2.VideoCapture(0)
fourcc = cv2.VideoWriter_fourcc(*'XVID')
op = cv2.VideoWriter('Sample1.avi', fourcc, 11.0, (640, 480))
while True:
ret, frame = capture.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow('frame', frame)
op.write(frame)
if cv2.waitKey(1) & 0xFF == ord('e'):
break
op.release()
capture.release()
cv2.destroyAllWindows()
def webdet():
capture = cv2.VideoCapture(0)
face_cascade = cv2.CascadeClassifier('lbpcascade_frontalface.xml')
eye_glass = cv2.CascadeClassifier('haarcascade_eye_tree_eyeglasses.xml')
while True:
ret, frame = capture.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray)
for (x, y, w, h) in faces:
font = cv2.FONT_HERSHEY_COMPLEX
cv2.putText(frame, 'Face', (x + w, y + h), font, 1, (250, 250, 250), 2, cv2.LINE_AA)
cv2.rectangle(frame, (x, y), (x + w, y + h), (255, 0, 0), 2)
roi_gray = gray[y:y + h, x:x + w]
roi_color = frame[y:y + h, x:x + w]
eye_g = eye_glass.detectMultiScale(roi_gray)
for (ex, ey, ew, eh) in eye_g:
cv2.rectangle(roi_color, (ex, ey), (ex + ew, ey + eh), (0, 255, 0), 2)
cv2.imshow('frame', frame)
if cv2.waitKey(1) & 0xff == ord('e'):
break
capture.release()
cv2.destroyAllWindows()
def webdetRec():
capture = cv2.VideoCapture(0)
face_cascade = cv2.CascadeClassifier('lbpcascade_frontalface.xml')
eye_glass = cv2.CascadeClassifier('haarcascade_eye_tree_eyeglasses.xml')
fourcc = cv2.VideoWriter_fourcc(*'XVID')
op = cv2.VideoWriter('Sample2.avi', fourcc, 9.0, (640, 480))
while True:
ret, frame = capture.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray)
for (x, y, w, h) in faces:
font = cv2.FONT_HERSHEY_COMPLEX
cv2.putText(frame, 'Face', (x + w, y + h), font, 1, (250, 250, 250), 2, cv2.LINE_AA)
cv2.rectangle(frame, (x, y), (x + w, y + h), (255, 0, 0), 2)
roi_gray = gray[y:y + h, x:x + w]
roi_color = frame[y:y + h, x:x + w]
eye_g = eye_glass.detectMultiScale(roi_gray)
for (ex, ey, ew, eh) in eye_g:
cv2.rectangle(roi_color, (ex, ey), (ex + ew, ey + eh), (0, 255, 0), 2)
op.write(frame)
cv2.imshow('frame', frame)
if cv2.waitKey(1) & 0xff == ord('e'):
break
op.release()
capture.release()
cv2.destroyAllWindows()
def alert():
mixer.init()
alert = mixer.Sound('beep-07.wav')
alert.play()
time.sleep(0.1)
alert.play()
def blink():
capture = cv2.VideoCapture(0)
face_cascade = cv2.CascadeClassifier('lbpcascade_frontalface.xml')
eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')
blink_cascade = cv2.CascadeClassifier('CustomBlinkCascade.xml')
while True:
ret, frame = capture.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray)
for (x, y, w, h) in faces:
font = cv2.FONT_HERSHEY_COMPLEX
cv2.putText(frame, 'Face', (x + w, y + h), font, 1, (250, 250, 250), 2, cv2.LINE_AA)
cv2.rectangle(frame, (x, y), (x + w, y + h), (255, 0, 0), 2)
roi_gray = gray[y:y + h, x:x + w]
roi_color = frame[y:y + h, x:x + w]
eyes = eye_cascade.detectMultiScale(roi_gray)
for (ex, ey, ew, eh) in eyes:
cv2.rectangle(roi_color, (ex, ey), (ex + ew, ey + eh), (0, 255, 0), 2)
blink = blink_cascade.detectMultiScale(roi_gray)
for (eyx, eyy, eyw, eyh) in blink:
cv2.rectangle(roi_color, (eyx, eyy), (eyx + eyw, eyy + eyh), (255, 255, 0), 2)
alert()
cv2.imshow('frame', frame)
if cv2.waitKey(1) & 0xFF == ord('e'):
break
capture.release()
cv2.destroyAllWindows()
def web():
capture = cv2.VideoCapture(0)
# Increase brightness and contrast (you can adjust the values as needed)
capture.set(cv2.CAP_PROP_BRIGHTNESS, 0.7)
capture.set(cv2.CAP_PROP_CONTRAST, 0.8)
global prev_time
global eyes_closed_counter
global yawning_counter
global head_down_counter
while True:
ret, frame = capture.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Call the check_eyes_yawn_head function to perform checks
check_eyes_yawn_head(frame)
cv2.imshow('frame', frame)
if cv2.waitKey(1) & 0xFF == ord('e'):
break
capture.release()
cv2.destroyAllWindows()
but1 = Button(frame, padx=5, pady=5, width=30, bg='white', fg='black', relief=GROOVE,
command=web, text='Click to Open Camera',
font=('helvetica 14 bold'))
but1.place(x=5, y=104)
but2 = Button(frame, padx=5, pady=5, width=30, bg='white', fg='black', relief=GROOVE,
command=webrec,
text='Click to Open Camera & Record', font=('helvetica 14 bold'))
but2.place(x=5, y=176)
but3 = Button(frame, padx=5, pady=5, width=30, bg='white', fg='black', relief=GROOVE,
command=webdet,
text='Click to Open Camera & Detect', font=('helvetica 14 bold'))
but3.place(x=5, y=250)
but4 = Button(frame, padx=5, pady=5, width=30, bg='white', fg='#74B0D6', relief=GROOVE,
command=webdetRec,
text='Detect & Record', font=('helvetica 14 bold'))
but4.place(x=5, y=322)
but5 = Button(frame, padx=5, pady=5, width=30, bg='white', fg='#74B0D6', relief=GROOVE,
command=blink,
text='Eye Blink Detect & Output Sound', font=('helvetica 14 bold'))
but5.place(x=5, y=400)
but5 = Button(frame, padx=4, pady=5, width=5, bg='red', fg='black', relief=GROOVE,
text='EXIT', command=exitt,
font=('helvetica 14 bold'))
but5.place(x=210, y=478)
root.mainloop()

More Related Content

Similar to You are task to add a yawning detection to the programme below;i.pdf

Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1Ke Wei Louis
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring CanvasKevin Hoyt
 
Introduction to Game Programming Tutorial
Introduction to Game Programming TutorialIntroduction to Game Programming Tutorial
Introduction to Game Programming TutorialRichard Jones
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manualUma mohan
 
Can someone please explain what the code below is doing and comment on.pdf
Can someone please explain what the code below is doing and comment on.pdfCan someone please explain what the code below is doing and comment on.pdf
Can someone please explain what the code below is doing and comment on.pdfkuldeepkumarapgsi
 
Current Score – 0 Due Wednesday, November 19 2014 0400 .docx
Current Score  –  0 Due  Wednesday, November 19 2014 0400 .docxCurrent Score  –  0 Due  Wednesday, November 19 2014 0400 .docx
Current Score – 0 Due Wednesday, November 19 2014 0400 .docxfaithxdunce63732
 
Create a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdfCreate a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdfarihantmobileselepun
 
The Ring programming language version 1.5.2 book - Part 29 of 181
The Ring programming language version 1.5.2 book - Part 29 of 181The Ring programming language version 1.5.2 book - Part 29 of 181
The Ring programming language version 1.5.2 book - Part 29 of 181Mahmoud Samir Fayed
 
Data structures KTU chapter2.PPT
Data structures KTU chapter2.PPTData structures KTU chapter2.PPT
Data structures KTU chapter2.PPTAlbin562191
 
Raspberry Pi à la GroovyFX
Raspberry Pi à la GroovyFXRaspberry Pi à la GroovyFX
Raspberry Pi à la GroovyFXStephen Chin
 
Python 내장 함수
Python 내장 함수Python 내장 함수
Python 내장 함수용 최
 
The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196Mahmoud Samir Fayed
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring CanvasKevin Hoyt
 
Standford 2015 week3: Objective-C Compatibility, Property List, Views
Standford 2015 week3: Objective-C Compatibility, Property List, ViewsStandford 2015 week3: Objective-C Compatibility, Property List, Views
Standford 2015 week3: Objective-C Compatibility, Property List, Views彼得潘 Pan
 
ECMAScript 6 major changes
ECMAScript 6 major changesECMAScript 6 major changes
ECMAScript 6 major changeshayato
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with ClojureDmitry Buzdin
 
The Ring programming language version 1.5.2 book - Part 41 of 181
The Ring programming language version 1.5.2 book - Part 41 of 181The Ring programming language version 1.5.2 book - Part 41 of 181
The Ring programming language version 1.5.2 book - Part 41 of 181Mahmoud Samir Fayed
 
The Ring programming language version 1.2 book - Part 32 of 84
The Ring programming language version 1.2 book - Part 32 of 84The Ring programming language version 1.2 book - Part 32 of 84
The Ring programming language version 1.2 book - Part 32 of 84Mahmoud Samir Fayed
 

Similar to You are task to add a yawning detection to the programme below;i.pdf (20)

Super Advanced Python –act1
Super Advanced Python –act1Super Advanced Python –act1
Super Advanced Python –act1
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring Canvas
 
Introduction to Game Programming Tutorial
Introduction to Game Programming TutorialIntroduction to Game Programming Tutorial
Introduction to Game Programming Tutorial
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
 
Can someone please explain what the code below is doing and comment on.pdf
Can someone please explain what the code below is doing and comment on.pdfCan someone please explain what the code below is doing and comment on.pdf
Can someone please explain what the code below is doing and comment on.pdf
 
Current Score – 0 Due Wednesday, November 19 2014 0400 .docx
Current Score  –  0 Due  Wednesday, November 19 2014 0400 .docxCurrent Score  –  0 Due  Wednesday, November 19 2014 0400 .docx
Current Score – 0 Due Wednesday, November 19 2014 0400 .docx
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
 
SCIPY-SYMPY.pdf
SCIPY-SYMPY.pdfSCIPY-SYMPY.pdf
SCIPY-SYMPY.pdf
 
Create a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdfCreate a java project that - Draw a circle with three random init.pdf
Create a java project that - Draw a circle with three random init.pdf
 
The Ring programming language version 1.5.2 book - Part 29 of 181
The Ring programming language version 1.5.2 book - Part 29 of 181The Ring programming language version 1.5.2 book - Part 29 of 181
The Ring programming language version 1.5.2 book - Part 29 of 181
 
Data structures KTU chapter2.PPT
Data structures KTU chapter2.PPTData structures KTU chapter2.PPT
Data structures KTU chapter2.PPT
 
Raspberry Pi à la GroovyFX
Raspberry Pi à la GroovyFXRaspberry Pi à la GroovyFX
Raspberry Pi à la GroovyFX
 
Python 내장 함수
Python 내장 함수Python 내장 함수
Python 내장 함수
 
The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196The Ring programming language version 1.7 book - Part 48 of 196
The Ring programming language version 1.7 book - Part 48 of 196
 
Exploring Canvas
Exploring CanvasExploring Canvas
Exploring Canvas
 
Standford 2015 week3: Objective-C Compatibility, Property List, Views
Standford 2015 week3: Objective-C Compatibility, Property List, ViewsStandford 2015 week3: Objective-C Compatibility, Property List, Views
Standford 2015 week3: Objective-C Compatibility, Property List, Views
 
ECMAScript 6 major changes
ECMAScript 6 major changesECMAScript 6 major changes
ECMAScript 6 major changes
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
The Ring programming language version 1.5.2 book - Part 41 of 181
The Ring programming language version 1.5.2 book - Part 41 of 181The Ring programming language version 1.5.2 book - Part 41 of 181
The Ring programming language version 1.5.2 book - Part 41 of 181
 
The Ring programming language version 1.2 book - Part 32 of 84
The Ring programming language version 1.2 book - Part 32 of 84The Ring programming language version 1.2 book - Part 32 of 84
The Ring programming language version 1.2 book - Part 32 of 84
 

More from sales223546

XML, XSDCreate an XML file that satisfies the following schema..pdf
XML, XSDCreate an XML file that satisfies the following schema..pdfXML, XSDCreate an XML file that satisfies the following schema..pdf
XML, XSDCreate an XML file that satisfies the following schema..pdfsales223546
 
Write the code in C, here is the template providedThe input used .pdf
Write the code in C, here is the template providedThe input used .pdfWrite the code in C, here is the template providedThe input used .pdf
Write the code in C, here is the template providedThe input used .pdfsales223546
 
Write ItemList.h and ItemList.cItemList is used to store a list .pdf
Write ItemList.h and ItemList.cItemList is used to store a list .pdfWrite ItemList.h and ItemList.cItemList is used to store a list .pdf
Write ItemList.h and ItemList.cItemList is used to store a list .pdfsales223546
 
Write a python script that will perform these operations procedurall.pdf
Write a python script that will perform these operations procedurall.pdfWrite a python script that will perform these operations procedurall.pdf
Write a python script that will perform these operations procedurall.pdfsales223546
 
Write a Python program that allows users to keep track of soccer pla.pdf
Write a Python program that allows users to keep track of soccer pla.pdfWrite a Python program that allows users to keep track of soccer pla.pdf
Write a Python program that allows users to keep track of soccer pla.pdfsales223546
 
Will upvote asapPlease help my code gives me incorrect val.pdf
Will upvote asapPlease help my code gives me incorrect val.pdfWill upvote asapPlease help my code gives me incorrect val.pdf
Will upvote asapPlease help my code gives me incorrect val.pdfsales223546
 
Who started the apple organization What were they doing at the time.pdf
Who started the apple organization What were they doing at the time.pdfWho started the apple organization What were they doing at the time.pdf
Who started the apple organization What were they doing at the time.pdfsales223546
 
Which supervision conditions are pertinent to these sex offenders.pdf
Which supervision conditions are pertinent to these sex offenders.pdfWhich supervision conditions are pertinent to these sex offenders.pdf
Which supervision conditions are pertinent to these sex offenders.pdfsales223546
 
Which of the following is a form of market participation A. The South.pdf
Which of the following is a form of market participation A. The South.pdfWhich of the following is a form of market participation A. The South.pdf
Which of the following is a form of market participation A. The South.pdfsales223546
 
Which of the following is a form of market participation A) the.pdf
Which of the following is a form of market participation A) the.pdfWhich of the following is a form of market participation A) the.pdf
Which of the following is a form of market participation A) the.pdfsales223546
 
Week 6 Class Assessment Implementation Plan for an HRD Learning Int.pdf
Week 6 Class Assessment Implementation Plan for an HRD Learning Int.pdfWeek 6 Class Assessment Implementation Plan for an HRD Learning Int.pdf
Week 6 Class Assessment Implementation Plan for an HRD Learning Int.pdfsales223546
 
Water restored in parts of Tshwane after two-day outagePretoria - .pdf
Water restored in parts of Tshwane after two-day outagePretoria - .pdfWater restored in parts of Tshwane after two-day outagePretoria - .pdf
Water restored in parts of Tshwane after two-day outagePretoria - .pdfsales223546
 
Venture Investors Bet AI Can Improve Supply-Chain ManagementLogist.pdf
Venture Investors Bet AI Can Improve Supply-Chain ManagementLogist.pdfVenture Investors Bet AI Can Improve Supply-Chain ManagementLogist.pdf
Venture Investors Bet AI Can Improve Supply-Chain ManagementLogist.pdfsales223546
 
using draw.io You are tasked with designing a database for a Movie.pdf
using draw.io You are tasked with designing a database for a Movie.pdfusing draw.io You are tasked with designing a database for a Movie.pdf
using draw.io You are tasked with designing a database for a Movie.pdfsales223546
 
Using jQuery, set up functionality to capture the forms input eleme.pdf
Using jQuery, set up functionality to capture the forms input eleme.pdfUsing jQuery, set up functionality to capture the forms input eleme.pdf
Using jQuery, set up functionality to capture the forms input eleme.pdfsales223546
 
using draw.io Task 3 Design an ER Diagram for a Library Management .pdf
using draw.io Task 3 Design an ER Diagram for a Library Management .pdfusing draw.io Task 3 Design an ER Diagram for a Library Management .pdf
using draw.io Task 3 Design an ER Diagram for a Library Management .pdfsales223546
 
using draw.io Task 2 Design an ER Diagram for a Music Streaming.pdf
using draw.io Task 2 Design an ER Diagram for a Music Streaming.pdfusing draw.io Task 2 Design an ER Diagram for a Music Streaming.pdf
using draw.io Task 2 Design an ER Diagram for a Music Streaming.pdfsales223546
 
UnixLinux 1. Use screen shots or video to demonstrate the before an.pdf
UnixLinux 1. Use screen shots or video to demonstrate the before an.pdfUnixLinux 1. Use screen shots or video to demonstrate the before an.pdf
UnixLinux 1. Use screen shots or video to demonstrate the before an.pdfsales223546
 
use python Problem 2. Selection Sort In this problem you will implem.pdf
use python Problem 2. Selection Sort In this problem you will implem.pdfuse python Problem 2. Selection Sort In this problem you will implem.pdf
use python Problem 2. Selection Sort In this problem you will implem.pdfsales223546
 

More from sales223546 (19)

XML, XSDCreate an XML file that satisfies the following schema..pdf
XML, XSDCreate an XML file that satisfies the following schema..pdfXML, XSDCreate an XML file that satisfies the following schema..pdf
XML, XSDCreate an XML file that satisfies the following schema..pdf
 
Write the code in C, here is the template providedThe input used .pdf
Write the code in C, here is the template providedThe input used .pdfWrite the code in C, here is the template providedThe input used .pdf
Write the code in C, here is the template providedThe input used .pdf
 
Write ItemList.h and ItemList.cItemList is used to store a list .pdf
Write ItemList.h and ItemList.cItemList is used to store a list .pdfWrite ItemList.h and ItemList.cItemList is used to store a list .pdf
Write ItemList.h and ItemList.cItemList is used to store a list .pdf
 
Write a python script that will perform these operations procedurall.pdf
Write a python script that will perform these operations procedurall.pdfWrite a python script that will perform these operations procedurall.pdf
Write a python script that will perform these operations procedurall.pdf
 
Write a Python program that allows users to keep track of soccer pla.pdf
Write a Python program that allows users to keep track of soccer pla.pdfWrite a Python program that allows users to keep track of soccer pla.pdf
Write a Python program that allows users to keep track of soccer pla.pdf
 
Will upvote asapPlease help my code gives me incorrect val.pdf
Will upvote asapPlease help my code gives me incorrect val.pdfWill upvote asapPlease help my code gives me incorrect val.pdf
Will upvote asapPlease help my code gives me incorrect val.pdf
 
Who started the apple organization What were they doing at the time.pdf
Who started the apple organization What were they doing at the time.pdfWho started the apple organization What were they doing at the time.pdf
Who started the apple organization What were they doing at the time.pdf
 
Which supervision conditions are pertinent to these sex offenders.pdf
Which supervision conditions are pertinent to these sex offenders.pdfWhich supervision conditions are pertinent to these sex offenders.pdf
Which supervision conditions are pertinent to these sex offenders.pdf
 
Which of the following is a form of market participation A. The South.pdf
Which of the following is a form of market participation A. The South.pdfWhich of the following is a form of market participation A. The South.pdf
Which of the following is a form of market participation A. The South.pdf
 
Which of the following is a form of market participation A) the.pdf
Which of the following is a form of market participation A) the.pdfWhich of the following is a form of market participation A) the.pdf
Which of the following is a form of market participation A) the.pdf
 
Week 6 Class Assessment Implementation Plan for an HRD Learning Int.pdf
Week 6 Class Assessment Implementation Plan for an HRD Learning Int.pdfWeek 6 Class Assessment Implementation Plan for an HRD Learning Int.pdf
Week 6 Class Assessment Implementation Plan for an HRD Learning Int.pdf
 
Water restored in parts of Tshwane after two-day outagePretoria - .pdf
Water restored in parts of Tshwane after two-day outagePretoria - .pdfWater restored in parts of Tshwane after two-day outagePretoria - .pdf
Water restored in parts of Tshwane after two-day outagePretoria - .pdf
 
Venture Investors Bet AI Can Improve Supply-Chain ManagementLogist.pdf
Venture Investors Bet AI Can Improve Supply-Chain ManagementLogist.pdfVenture Investors Bet AI Can Improve Supply-Chain ManagementLogist.pdf
Venture Investors Bet AI Can Improve Supply-Chain ManagementLogist.pdf
 
using draw.io You are tasked with designing a database for a Movie.pdf
using draw.io You are tasked with designing a database for a Movie.pdfusing draw.io You are tasked with designing a database for a Movie.pdf
using draw.io You are tasked with designing a database for a Movie.pdf
 
Using jQuery, set up functionality to capture the forms input eleme.pdf
Using jQuery, set up functionality to capture the forms input eleme.pdfUsing jQuery, set up functionality to capture the forms input eleme.pdf
Using jQuery, set up functionality to capture the forms input eleme.pdf
 
using draw.io Task 3 Design an ER Diagram for a Library Management .pdf
using draw.io Task 3 Design an ER Diagram for a Library Management .pdfusing draw.io Task 3 Design an ER Diagram for a Library Management .pdf
using draw.io Task 3 Design an ER Diagram for a Library Management .pdf
 
using draw.io Task 2 Design an ER Diagram for a Music Streaming.pdf
using draw.io Task 2 Design an ER Diagram for a Music Streaming.pdfusing draw.io Task 2 Design an ER Diagram for a Music Streaming.pdf
using draw.io Task 2 Design an ER Diagram for a Music Streaming.pdf
 
UnixLinux 1. Use screen shots or video to demonstrate the before an.pdf
UnixLinux 1. Use screen shots or video to demonstrate the before an.pdfUnixLinux 1. Use screen shots or video to demonstrate the before an.pdf
UnixLinux 1. Use screen shots or video to demonstrate the before an.pdf
 
use python Problem 2. Selection Sort In this problem you will implem.pdf
use python Problem 2. Selection Sort In this problem you will implem.pdfuse python Problem 2. Selection Sort In this problem you will implem.pdf
use python Problem 2. Selection Sort In this problem you will implem.pdf
 

Recently uploaded

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 

Recently uploaded (20)

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 

You are task to add a yawning detection to the programme below;i.pdf

  • 1. You are task to add a yawning detection to the programme below; import numpy as np from pygame import mixer import time import cv2 from tkinter import * import tkinter.messagebox import mysql.connector from datetime import datetime root = Tk() root.geometry('500x570') frame = Frame(root, relief=RIDGE, borderwidth=2) frame.pack(fill=BOTH, expand=1) root.title('Drive Main') frame.config(background='#74B0D6') label = Label(frame, text="Drive Care", bg='#74B0D6', font='Garcedo 25 bold') label.pack(side=TOP) filename = PhotoImage(file="picco.png") background_label = Label(frame, image=filename) background_label.pack(side=TOP) from mysql.connector import Error def connect(): """ Connect to MySQL database """ conn = None try: conn = mysql.connector.connect(host='localhost', database='drive_main', user='root', password='') mySql_insert_query = """INSERT INTO tbl_drivers(id, name, event_time) VALUES (%s, %s, %s) """
  • 2. cursor = conn.cursor() current_Date = datetime.now() # convert date in the format you want formatted_date = current_Date.strftime('%Y-%m-%d %H:%M:%S') insert_tuple = (5, 'meleda ulett', current_Date) result = cursor.execute(mySql_insert_query, insert_tuple) conn.commit() print("Date Record inserted successfully") if conn.is_connected(): print('Connected to MySQL database') except Error as e: print(e) except mysql.connector.Error as error: conn.rollback() print("Failed to insert into MySQL table {}".format(error)) finally: if conn is not None and conn.is_connected(): conn.close() connect() def hel_doc(): help(cv2) def Contri(): tkinter.messagebox.showinfo("Contributors", "n1.Romairo Reidn2. Kayla-Marie Sooman n3. Bradly Walcott n4. Lee Hinds n") def anotherWin(): tkinter.messagebox.showinfo("About", 'Drive Care version 01.1n Made Usingn-OpenCVnpn-Tkintern In Python 3') menu = Menu(root) root.config(menu=menu)
  • 3. subm1 = Menu(menu) menu.add_cascade(label="Tools", menu=subm1) subm1.add_command(label="Open CV Docs", command=hel_doc) subm2 = Menu(menu) menu.add_cascade(label="About", menu=subm2) subm2.add_command(label="Driver Cam", command=anotherWin) subm2.add_command(label="Contributors", command=Contri) def exitt(): exit() def web(): capture = cv2.VideoCapture(0) while True: ret, frame = capture.read() gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) cv2.imshow('frame', frame) if cv2.waitKey(1) & 0xFF == ord('e'): break capture.release() cv2.destroyAllWindows() def webrec(): capture = cv2.VideoCapture(0) fourcc = cv2.VideoWriter_fourcc(*'XVID') op = cv2.VideoWriter('Sample1.avi', fourcc, 11.0, (640, 480)) while True: ret, frame = capture.read() gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) cv2.imshow('frame', frame) op.write(frame) if cv2.waitKey(1) & 0xFF == ord('e'): break op.release() capture.release() cv2.destroyAllWindows()
  • 4. def webdet(): capture = cv2.VideoCapture(0) face_cascade = cv2.CascadeClassifier('lbpcascade_frontalface.xml') eye_glass = cv2.CascadeClassifier('haarcascade_eye_tree_eyeglasses.xml') while True: ret, frame = capture.read() gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) faces = face_cascade.detectMultiScale(gray) for (x, y, w, h) in faces: font = cv2.FONT_HERSHEY_COMPLEX cv2.putText(frame, 'Face', (x + w, y + h), font, 1, (250, 250, 250), 2, cv2.LINE_AA) cv2.rectangle(frame, (x, y), (x + w, y + h), (255, 0, 0), 2) roi_gray = gray[y:y + h, x:x + w] roi_color = frame[y:y + h, x:x + w] eye_g = eye_glass.detectMultiScale(roi_gray) for (ex, ey, ew, eh) in eye_g: cv2.rectangle(roi_color, (ex, ey), (ex + ew, ey + eh), (0, 255, 0), 2) cv2.imshow('frame', frame) if cv2.waitKey(1) & 0xff == ord('e'): break capture.release() cv2.destroyAllWindows() def webdetRec(): capture = cv2.VideoCapture(0) face_cascade = cv2.CascadeClassifier('lbpcascade_frontalface.xml') eye_glass = cv2.CascadeClassifier('haarcascade_eye_tree_eyeglasses.xml') fourcc = cv2.VideoWriter_fourcc(*'XVID') op = cv2.VideoWriter('Sample2.avi', fourcc, 9.0, (640, 480)) while True: ret, frame = capture.read() gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) faces = face_cascade.detectMultiScale(gray) for (x, y, w, h) in faces: font = cv2.FONT_HERSHEY_COMPLEX
  • 5. cv2.putText(frame, 'Face', (x + w, y + h), font, 1, (250, 250, 250), 2, cv2.LINE_AA) cv2.rectangle(frame, (x, y), (x + w, y + h), (255, 0, 0), 2) roi_gray = gray[y:y + h, x:x + w] roi_color = frame[y:y + h, x:x + w] eye_g = eye_glass.detectMultiScale(roi_gray) for (ex, ey, ew, eh) in eye_g: cv2.rectangle(roi_color, (ex, ey), (ex + ew, ey + eh), (0, 255, 0), 2) op.write(frame) cv2.imshow('frame', frame) if cv2.waitKey(1) & 0xff == ord('e'): break op.release() capture.release() cv2.destroyAllWindows() def alert(): mixer.init() alert = mixer.Sound('beep-07.wav') alert.play() time.sleep(0.1) alert.play() def blink(): capture = cv2.VideoCapture(0) face_cascade = cv2.CascadeClassifier('lbpcascade_frontalface.xml') eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml') blink_cascade = cv2.CascadeClassifier('CustomBlinkCascade.xml') while True: ret, frame = capture.read() gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) faces = face_cascade.detectMultiScale(gray) for (x, y, w, h) in faces: font = cv2.FONT_HERSHEY_COMPLEX cv2.putText(frame, 'Face', (x + w, y + h), font, 1, (250, 250, 250), 2, cv2.LINE_AA) cv2.rectangle(frame, (x, y), (x + w, y + h), (255, 0, 0), 2) roi_gray = gray[y:y + h, x:x + w]
  • 6. roi_color = frame[y:y + h, x:x + w] eyes = eye_cascade.detectMultiScale(roi_gray) for (ex, ey, ew, eh) in eyes: cv2.rectangle(roi_color, (ex, ey), (ex + ew, ey + eh), (0, 255, 0), 2) blink = blink_cascade.detectMultiScale(roi_gray) for (eyx, eyy, eyw, eyh) in blink: cv2.rectangle(roi_color, (eyx, eyy), (eyx + eyw, eyy + eyh), (255, 255, 0), 2) alert() cv2.imshow('frame', frame) if cv2.waitKey(1) & 0xFF == ord('e'): break capture.release() cv2.destroyAllWindows() def web(): capture = cv2.VideoCapture(0) # Increase brightness and contrast (you can adjust the values as needed) capture.set(cv2.CAP_PROP_BRIGHTNESS, 0.7) capture.set(cv2.CAP_PROP_CONTRAST, 0.8) global prev_time global eyes_closed_counter global yawning_counter global head_down_counter while True: ret, frame = capture.read() gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # Call the check_eyes_yawn_head function to perform checks check_eyes_yawn_head(frame) cv2.imshow('frame', frame) if cv2.waitKey(1) & 0xFF == ord('e'): break capture.release() cv2.destroyAllWindows() but1 = Button(frame, padx=5, pady=5, width=30, bg='white', fg='black', relief=GROOVE, command=web, text='Click to Open Camera', font=('helvetica 14 bold'))
  • 7. but1.place(x=5, y=104) but2 = Button(frame, padx=5, pady=5, width=30, bg='white', fg='black', relief=GROOVE, command=webrec, text='Click to Open Camera & Record', font=('helvetica 14 bold')) but2.place(x=5, y=176) but3 = Button(frame, padx=5, pady=5, width=30, bg='white', fg='black', relief=GROOVE, command=webdet, text='Click to Open Camera & Detect', font=('helvetica 14 bold')) but3.place(x=5, y=250) but4 = Button(frame, padx=5, pady=5, width=30, bg='white', fg='#74B0D6', relief=GROOVE, command=webdetRec, text='Detect & Record', font=('helvetica 14 bold')) but4.place(x=5, y=322) but5 = Button(frame, padx=5, pady=5, width=30, bg='white', fg='#74B0D6', relief=GROOVE, command=blink, text='Eye Blink Detect & Output Sound', font=('helvetica 14 bold')) but5.place(x=5, y=400) but5 = Button(frame, padx=4, pady=5, width=5, bg='red', fg='black', relief=GROOVE, text='EXIT', command=exitt, font=('helvetica 14 bold')) but5.place(x=210, y=478) root.mainloop()