Git Product home page Git Product logo

-python's People

Contributors

wanghuachen avatar

Watchers

 avatar

-python's Issues

'_dlib_pybind11.rectangles' object is not callable

import cv2
import dlib
from scipy.spatial import distance

def calculate_EAR(eye):
A=distance.euclidean(eye[1],eye[5])
B=distance.euclidean(eye[2],eye[4])
C=distance.euclidean(eye[0],eye[3])
ear_aspect_ratio=(A+B)/(2.0*C)
return ear_aspect_ratio

cap=cv2.VideoCapture('F:/python learning/whc-opencv/WLR.jpg')
hog_face_detector=dlib.get_frontal_face_detector()
dlib_facelandmark=dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")

while(True):
ret,frame=cap.read()
gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)

faces=hog_face_detector(gray,0)

for face in faces():

face_landmarks=dlib_facelandmark(gray,face)
leftEye=[]
rightEye=[]

for n in range(36,42):
    x=face_landmarks.part(n).x
    y=face_landmarks.part(n).y
    leftEye.append((x,y))
    next_point=n+1
    if n==41:
        next_point=36
    x2=face_landmarks.part(next_point).x
    y2=face_landmarks.part(next_point).y
    cv2.line(frame,(x,y),(x2,y2),(0,255,0),1)

for n in range(42,48):
    x = face_landmarks.part(n).x
    y = face_landmarks.part(n).y
    rightEye.append((x, y))
    next_point = n + 1
    if n == 47:
        next_point = 42
    x2 = face_landmarks.part(next_point).x
    y2 = face_landmarks.part(next_point).y
    cv2.line(frame, (x, y), (x2, y2), (0, 255, 0), 1)
print(leftEye)
print(rightEye)
left_ear=calculate_EAR(leftEye)
right_ear=calculate_EAR(rightEye)

EAR=(left_ear+right_ear)/2
EAR=round(EAR,2)
if EAR<0.26:
    cv2.putText(frame,'DROWSY',(20,100),cv2.FONT_HERSHEY_SCRIPT_SIMPLEX,3,(0,0,255),4)
    cv2.putText(frame, 'Are you Sleeoy?', (20, 100), cv2.FONT_HERSHEY_SCRIPT_SIMPLEX, 2, (0, 0, 255), 4)
    print('DROWSY')

print(EAR)

cv2.imshow('Are you Sleepy',frame)

key=cv2.waitKey(1)
if key==27:
break

cap.release()
cv2.destroyAllWindows()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.