当前位置:网站首页>Dlib library blink
Dlib library blink
2022-06-30 08:03:00 【emplace_ back】
See the comments
import cv2 as cv
import dlib
import imutils
import numpy as np
from imutils import face_utils as fu
def eye_aspect_ratio(eye):
# Calculate the Euclidean distance up and down
a = np.linalg.norm(eye[1] - eye[5])
b = np.linalg.norm(eye[2] - eye[4])
# Calculate the left and right Euclidean distance
c = np.linalg.norm(eye[0] - eye[3])
# Calculate the aspect ratio and return
d = (a + b) / (2.0 * c)
return d
COUNTER = 0
TOTAL = 0
# Turn on the camera
cap = cv.VideoCapture(0, cv.CAP_DSHOW)
# Establish a face detector
detector = dlib.get_frontal_face_detector()
# establish 68 Key point detector
predictor = dlib.shape_predictor('./1.dat')
# Returns the left and right eyes of the face 68 Start and end in key points
(lStart, lEnd) = fu.FACIAL_LANDMARKS_IDXS["left_eye"]
(rStart, rEnd) = fu.FACIAL_LANDMARKS_IDXS["right_eye"]
# As long as the camera can be turned on correctly
while cap.isOpened():
# Get every frame
_, frame = cap.read()
# Set output width
frame = imutils.resize(frame, width=750)
# Convert to gray image to speed up recognition
gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
# Return all face frames of this frame
faces = detector(gray, 0)
# Traverse all frames
for face in faces:
# Returns the of the box 68 A coordinate
shape = predictor(gray, face)
# Into a coordinate matrix
shape = fu.shape_to_np(shape)
# Returns the coordinates of the left and right eyes
leftEye = shape[lStart:lEnd]
rightEye = shape[rStart:rEnd]
# Calculate the aspect ratio of the left eye and the right eye
leftEAR = eye_aspect_ratio(leftEye)
rightEAR = eye_aspect_ratio(rightEye)
# Average.
earAVG = (leftEAR + rightEAR) / 2.0
# Calculate the convex hull of the left and right eyes
leftEyeHull = cv.convexHull(leftEye)
rightEyeHull = cv.convexHull(rightEye)
# Circle the convex hull , That is, the scope of the eyes
cv.drawContours(frame, [leftEyeHull], -1, (255, 255, 255), 1)
cv.drawContours(frame, [rightEyeHull], -1, (255, 255, 255), 1)
''' If the aspect ratio of the eye is less than 0.3 And continuity 3 frame I think I close my eyes '''
if earAVG < 0.3:
COUNTER += 1
else:
if COUNTER >= 3:
TOTAL += 1
COUNTER = 0
# Next is the processing of the output
# Output blink times in the upper left corner
cv.putText(
frame,
"Blinks:{0}".format(TOTAL),
(10, 20),
cv.FONT_HERSHEY_COMPLEX_SMALL,
1,
(255, 255, 255),
2,
cv.LINE_AA
)
# Immediate real time earAVG
cv.putText(
frame,
"earAVG:{0}".format(earAVG),
(200, 20),
cv.FONT_HERSHEY_COMPLEX_SMALL,
1,
(255, 255, 255),
2,
cv.LINE_AA
)
# The lower right corner prompts the exit message
cv.putText(
frame,
"Press 'Esc' to Quit",
(515, 550),
cv.FONT_HERSHEY_COMPLEX_SMALL,
1,
(255, 255, 255),
2,
cv.LINE_AA
)
# Output every frame
cv.imshow('camera', frame)
# Press Esc sign out
if cv.waitKey(1) & 0xff == 27:
break
# Close all windows
cv.destroyAllWindows()
# Release camera
cap.release()
边栏推荐
- December 4, 2021 [metagenome] - sorting out the progress of metagenome process construction
- Construction of module 5 of actual combat Battalion
- What management improvements can CRM bring to enterprises
- Deep learning -- feature point detection and target detection
- HelloWorld
- Final review -php learning notes 4-php custom functions
- Permutation and combination of probability
- 【花雕体验】14 行空板pinpong库测试外接传感器模块(之一)
- Full stack performance testing theory - Summary
- Lexicographic order -- full arrangement in bell sound
猜你喜欢

1162 Postfix Expression
![November 22, 2021 [reading notes] - bioinformatics and functional genomics (Chapter 5, section 4, hidden Markov model)](/img/0d/77953ffa9f45a5acc16f02bf33293b.jpg)
November 22, 2021 [reading notes] - bioinformatics and functional genomics (Chapter 5, section 4, hidden Markov model)

微信小程序使用vant weapp报错
![November 21, 2021 [reading notes] - bioinformatics and functional genomics (Chapter 5 advanced database search)](/img/20/bbb6e740df96250016147c54bc6cc1.jpg)
November 21, 2021 [reading notes] - bioinformatics and functional genomics (Chapter 5 advanced database search)

深度学习——嵌入矩阵and学习词嵌入andWord2Vec
![2021-10-29 [microbiology] a complete set of 16s/its analysis process based on qiime2 tool (Part I)](/img/9d/37c531b1b439770f69f715687685f5.jpg)
2021-10-29 [microbiology] a complete set of 16s/its analysis process based on qiime2 tool (Part I)

深度学习——序列模型and数学符号

亚马逊测评术语有哪些?

Deep learning -- using word embedding and word embedding features

Efga design open source framework fabulous series (I) establishment of development environment
随机推荐
Efga design open source framework fabulous series (I) establishment of development environment
Tue Jun 28 2022 15:30:29 gmt+0800 (China standard time) date formatting
CRM能为企业带来哪些管理提升
Analysis of cross clock transmission in tinyriscv
2021-10-29 [microbiology] a complete set of 16s/its analysis process based on qiime2 tool (Part I)
深度学习——卷积的滑动窗口实现
深度学习——嵌入矩阵and学习词嵌入andWord2Vec
Experiment 2 LED button PWM 2021/11/15
Opencv4.2.0+vs2015 configuration
More, faster, better and cheaper. Here comes the fastdeploy beta of the low threshold AI deployment tool!
Deep learning -- using word embedding and word embedding features
Introduction notes to pytorch deep learning (10) neural network convolution layer
安科瑞高等学校校园建筑节能监管系统建设
6月底了,可以开始做准备了,不然这么赚钱的行业就没你的份了
1163 Dijkstra Sequence
1162 Postfix Expression
JS code case
【JUC系列】Fork/Join框架之概览
Want to change careers, but don't know what to do? This article is written for you who are confused
深度学习——语言模型和序列生成