- 1

anyone can help me for solving this code in opencv.

import cv2 as cv import dlib import time import numpy as np from imutils import face_utils import pygame pygame.mixer.init() EYE_ASPECT_RATIO_THRESHOLD=0.3 EYE_ASPECT_RATIO_CONSEC_FRAMES=50 # MINIMUM CONSECUTIVE FRAMES FoR WHICH EYE RATIO IS BELOW THRESHOLD FOR AlARM To BE TRIGGERED COUNTER=0 face_cascade=cv.CascadeClassifier("haarcascades/haarcascade_frontalface_default.xml") eye_cascade=cv.CascadeClassifier("haarcascades/haarcascade_eye.xml") # this fn cacuate and return eye aspect rati def eye_aspect_ratio(eye): A = dist.euclidean(eye[1], eye[5]) B = dist.euclidean(eye[2], eye[4]) C = dist.euclidean(eye[0], eye[3]) ear = (A + B) / (2.0 * C) return ear # load face detector and predictor by using dlib shape predict file detector=dlib.get_frontal_face_detector() predictor=dlib.shape_predictor("shape_predictor_68_face_landmarks.dat") # start webcam tO videocapture video_capture=cv.VideoCapture(0) time.sleep(2) while True: ret,frame=video_capture.read() frame=cv.flip(frame,1)#flip gray=cv.cvtColor(frame,cv.COLOR_BGR2GRAY) # detect facial points through detector function faces=detector(gray,0) faces_rectangle=face_cascade.detectMultiScale(gray,1.3,5) for (x,y,w,h)in faces_rectangle: cv.rectangle(frame,(x,y),(x+w,y+h),(255,0,0),2) # to detect facial points for face in faces: shape=predictor(gray,face) shape=face_utils.shape_to_np(shape) leftEye=shape[lStart:lend] rightEye=shape[rStart:rend] left_eye_aspect_ratio=eye_aspect_ratio(leftEye) right_eye_aspect_ratio=eye_aspect_ratio(rightEye) eye_aspect_ratio=(left_eye_aspect_ratio+right_eye_aspect_ratio)/2 if eye_aspect_ratio<EYE_ASPECT_RATIO_THRESHOLD: COUNTER=+1 if COUNTER>EYE_ASPECT_RATIO_CONSEC_FRAMES: pygame.mixer.music.play(-1) cv2.putText(frame,"you are drowsi",(150,200),cv2.F

31st May 2021, 6:23 AM
haritha ph
haritha ph - avatar
2 Réponses
+ 2
Upload the code with proper method. No one is going to read this. AND you have not described your problem. https://www.sololearn.com/post/75089/?ref=app
31st May 2021, 6:38 AM
AKSHAY🇮🇳
AKSHAY🇮🇳 - avatar
0
also you have double posted this thread: https://www.sololearn.com/Discuss/2800304/?ref=app
31st May 2021, 3:09 PM
visph
visph - avatar