Skip to content

Commit

Permalink
添加dlib版视频识别
Browse files Browse the repository at this point in the history
  • Loading branch information
vipstone committed Apr 21, 2018
1 parent 9dffb77 commit e905c2d
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions faceai/videoDlib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# coding=utf-8
import cv2
import dlib

detector = dlib.get_frontal_face_detector() #使用默认的人类识别器模型


def discern(img):
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
dets = detector(gray, 1)
for face in dets:
left = face.left()
top = face.top()
right = face.right()
bottom = face.bottom()
cv2.rectangle(img, (left, top), (right, bottom), (0, 255, 0), 2)
cv2.imshow("image", img)


cap = cv2.VideoCapture(0)
while (1):
ret, img = cap.read()
discern(img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break

cap.release()
cv2.destroyAllWindows()

0 comments on commit e905c2d

Please sign in to comment.