1 Star 0 Fork 1

ZhenglinPan/Proctoring-AI

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
mouth_opening_detector.py 2.12 KB
一键复制 编辑 原始数据 按行查看 历史
vardanagarwal 提交于 2020-07-31 05:29 . Adding files
# -*- coding: utf-8 -*-
"""
Created on Fri Jul 31 01:04:44 2020
@author: hp
"""
import cv2
from face_detector import get_face_detector, find_faces
from face_landmarks import get_landmark_model, detect_marks, draw_marks
face_model = get_face_detector()
landmark_model = get_landmark_model()
outer_points = [[49, 59], [50, 58], [51, 57], [52, 56], [53, 55]]
d_outer = [0]*5
inner_points = [[61, 67], [62, 66], [63, 65]]
d_inner = [0]*3
font = cv2.FONT_HERSHEY_SIMPLEX
cap = cv2.VideoCapture(0)
while(True):
ret, img = cap.read()
rects = find_faces(img, face_model)
for rect in rects:
shape = detect_marks(img, landmark_model, rect)
draw_marks(img, shape)
cv2.putText(img, 'Press r to record Mouth distances', (30, 30), font,
1, (0, 255, 255), 2)
cv2.imshow("Output", img)
if cv2.waitKey(1) & 0xFF == ord('r'):
for i in range(100):
for i, (p1, p2) in enumerate(outer_points):
d_outer[i] += shape[p2][1] - shape[p1][1]
for i, (p1, p2) in enumerate(inner_points):
d_inner[i] += shape[p2][1] - shape[p1][1]
break
cv2.destroyAllWindows()
d_outer[:] = [x / 100 for x in d_outer]
d_inner[:] = [x / 100 for x in d_inner]
while(True):
ret, img = cap.read()
rects = find_faces(img, face_model)
for rect in rects:
shape = detect_marks(img, landmark_model, rect)
cnt_outer = 0
cnt_inner = 0
draw_marks(img, shape[48:])
for i, (p1, p2) in enumerate(outer_points):
if d_outer[i] + 3 < shape[p2][1] - shape[p1][1]:
cnt_outer += 1
for i, (p1, p2) in enumerate(inner_points):
if d_inner[i] + 2 < shape[p2][1] - shape[p1][1]:
cnt_inner += 1
if cnt_outer > 3 and cnt_inner > 2:
print('Mouth open')
cv2.putText(img, 'Mouth open', (30, 30), font,
1, (0, 255, 255), 2)
# show the output image with the face detections + facial landmarks
cv2.imshow("Output", img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ZhenglinPan/Proctoring-AI.git
git@gitee.com:ZhenglinPan/Proctoring-AI.git
ZhenglinPan
Proctoring-AI
Proctoring-AI
master

搜索帮助