forked from vipstone/faceai
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |