SlideShare a Scribd company logo
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

More from sales223546 (11)

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
sales223546
 
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
sales223546
 
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
sales223546
 
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
sales223546
 
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
sales223546
 
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
sales223546
 
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
sales223546
 
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
sales223546
 
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
sales223546
 
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
sales223546
 
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
sales223546
 
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
sales223546
 
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
sales223546
 
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
sales223546
 
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
sales223546
 
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
sales223546
 
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
sales223546
 
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
sales223546
 
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
sales223546
 
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
sales223546
 
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
sales223546
 
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
sales223546
 

Recently uploaded (20)

Launch of The State of Global Teenage Career Preparation - Andreas Schleicher...
Launch of The State of Global Teenage Career Preparation - Andreas Schleicher...Launch of The State of Global Teenage Career Preparation - Andreas Schleicher...
Launch of The State of Global Teenage Career Preparation - Andreas Schleicher...
EduSkills OECD
 
Antepartum fetal surveillance---Dr. H.K.Cheema pdf.pdf
Antepartum fetal surveillance---Dr. H.K.Cheema pdf.pdfAntepartum fetal surveillance---Dr. H.K.Cheema pdf.pdf
Antepartum fetal surveillance---Dr. H.K.Cheema pdf.pdf
Dr H.K. Cheema
 
Module_2_Types_and_Approaches_of_Research (2).pptx
Module_2_Types_and_Approaches_of_Research (2).pptxModule_2_Types_and_Approaches_of_Research (2).pptx
Module_2_Types_and_Approaches_of_Research (2).pptx
drroxannekemp
 
Rebuilding the library community in a post-Twitter world
Rebuilding the library community in a post-Twitter worldRebuilding the library community in a post-Twitter world
Rebuilding the library community in a post-Twitter world
Ned Potter
 
Letter to Secretary Linda McMahon from U.S. Senators
Letter to Secretary Linda McMahon from U.S. SenatorsLetter to Secretary Linda McMahon from U.S. Senators
Letter to Secretary Linda McMahon from U.S. Senators
Mebane Rash
 
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales moduleHow To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
Celine George
 
How to Configure Extra Steps During Checkout in Odoo 18 Website
How to Configure Extra Steps During Checkout in Odoo 18 WebsiteHow to Configure Extra Steps During Checkout in Odoo 18 Website
How to Configure Extra Steps During Checkout in Odoo 18 Website
Celine George
 
PUBH1000 Slides - Module 11: Governance for Health
PUBH1000 Slides - Module 11: Governance for HealthPUBH1000 Slides - Module 11: Governance for Health
PUBH1000 Slides - Module 11: Governance for Health
JonathanHallett4
 
How to Add Button in Chatter in Odoo 18 - Odoo Slides
How to Add Button in Chatter in Odoo 18 - Odoo SlidesHow to Add Button in Chatter in Odoo 18 - Odoo Slides
How to Add Button in Chatter in Odoo 18 - Odoo Slides
Celine George
 
The History of Kashmir Lohar Dynasty NEP.ppt
The History of Kashmir Lohar Dynasty NEP.pptThe History of Kashmir Lohar Dynasty NEP.ppt
The History of Kashmir Lohar Dynasty NEP.ppt
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
How to Manage Cross Selling in Odoo 18 Sales
How to Manage Cross Selling in Odoo 18 SalesHow to Manage Cross Selling in Odoo 18 Sales
How to Manage Cross Selling in Odoo 18 Sales
Celine George
 
EUPHORIA GENERAL QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025EUPHORIA GENERAL QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
EUPHORIA GENERAL QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 21 MARCH 2025
Quiz Club of PSG College of Arts & Science
 
Module 1: Foundations of Research
Module 1: Foundations of ResearchModule 1: Foundations of Research
Module 1: Foundations of Research
drroxannekemp
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-14-2025 .pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-14-2025  .pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-14-2025  .pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-14-2025 .pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
How to Manage Manual Reordering Rule in Odoo 18 Inventory
How to Manage Manual Reordering Rule in Odoo 18 InventoryHow to Manage Manual Reordering Rule in Odoo 18 Inventory
How to Manage Manual Reordering Rule in Odoo 18 Inventory
Celine George
 
IPL QUIZ | THE QUIZ CLUB OF PSGCAS | 2025.pdf
IPL QUIZ | THE QUIZ CLUB OF PSGCAS | 2025.pdfIPL QUIZ | THE QUIZ CLUB OF PSGCAS | 2025.pdf
IPL QUIZ | THE QUIZ CLUB OF PSGCAS | 2025.pdf
Quiz Club of PSG College of Arts & Science
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-17-2025 .pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-17-2025  .pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-17-2025  .pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-17-2025 .pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
PUBH1000 Slides - Module 12: Advocacy for Health
PUBH1000 Slides - Module 12: Advocacy for HealthPUBH1000 Slides - Module 12: Advocacy for Health
PUBH1000 Slides - Module 12: Advocacy for Health
JonathanHallett4
 
MICROBIAL GENETICS -tranformation and tranduction.pdf
MICROBIAL GENETICS -tranformation and tranduction.pdfMICROBIAL GENETICS -tranformation and tranduction.pdf
MICROBIAL GENETICS -tranformation and tranduction.pdf
DHARMENDRA SAHU
 
Search Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo SlidesSearch Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo Slides
Celine George
 
Launch of The State of Global Teenage Career Preparation - Andreas Schleicher...
Launch of The State of Global Teenage Career Preparation - Andreas Schleicher...Launch of The State of Global Teenage Career Preparation - Andreas Schleicher...
Launch of The State of Global Teenage Career Preparation - Andreas Schleicher...
EduSkills OECD
 
Antepartum fetal surveillance---Dr. H.K.Cheema pdf.pdf
Antepartum fetal surveillance---Dr. H.K.Cheema pdf.pdfAntepartum fetal surveillance---Dr. H.K.Cheema pdf.pdf
Antepartum fetal surveillance---Dr. H.K.Cheema pdf.pdf
Dr H.K. Cheema
 
Module_2_Types_and_Approaches_of_Research (2).pptx
Module_2_Types_and_Approaches_of_Research (2).pptxModule_2_Types_and_Approaches_of_Research (2).pptx
Module_2_Types_and_Approaches_of_Research (2).pptx
drroxannekemp
 
Rebuilding the library community in a post-Twitter world
Rebuilding the library community in a post-Twitter worldRebuilding the library community in a post-Twitter world
Rebuilding the library community in a post-Twitter world
Ned Potter
 
Letter to Secretary Linda McMahon from U.S. Senators
Letter to Secretary Linda McMahon from U.S. SenatorsLetter to Secretary Linda McMahon from U.S. Senators
Letter to Secretary Linda McMahon from U.S. Senators
Mebane Rash
 
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales moduleHow To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
Celine George
 
How to Configure Extra Steps During Checkout in Odoo 18 Website
How to Configure Extra Steps During Checkout in Odoo 18 WebsiteHow to Configure Extra Steps During Checkout in Odoo 18 Website
How to Configure Extra Steps During Checkout in Odoo 18 Website
Celine George
 
PUBH1000 Slides - Module 11: Governance for Health
PUBH1000 Slides - Module 11: Governance for HealthPUBH1000 Slides - Module 11: Governance for Health
PUBH1000 Slides - Module 11: Governance for Health
JonathanHallett4
 
How to Add Button in Chatter in Odoo 18 - Odoo Slides
How to Add Button in Chatter in Odoo 18 - Odoo SlidesHow to Add Button in Chatter in Odoo 18 - Odoo Slides
How to Add Button in Chatter in Odoo 18 - Odoo Slides
Celine George
 
How to Manage Cross Selling in Odoo 18 Sales
How to Manage Cross Selling in Odoo 18 SalesHow to Manage Cross Selling in Odoo 18 Sales
How to Manage Cross Selling in Odoo 18 Sales
Celine George
 
Module 1: Foundations of Research
Module 1: Foundations of ResearchModule 1: Foundations of Research
Module 1: Foundations of Research
drroxannekemp
 
How to Manage Manual Reordering Rule in Odoo 18 Inventory
How to Manage Manual Reordering Rule in Odoo 18 InventoryHow to Manage Manual Reordering Rule in Odoo 18 Inventory
How to Manage Manual Reordering Rule in Odoo 18 Inventory
Celine George
 
PUBH1000 Slides - Module 12: Advocacy for Health
PUBH1000 Slides - Module 12: Advocacy for HealthPUBH1000 Slides - Module 12: Advocacy for Health
PUBH1000 Slides - Module 12: Advocacy for Health
JonathanHallett4
 
MICROBIAL GENETICS -tranformation and tranduction.pdf
MICROBIAL GENETICS -tranformation and tranduction.pdfMICROBIAL GENETICS -tranformation and tranduction.pdf
MICROBIAL GENETICS -tranformation and tranduction.pdf
DHARMENDRA SAHU
 
Search Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo SlidesSearch Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo Slides
Celine George
 

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()
  翻译: