0
点赞
收藏
分享

微信扫一扫

[python][deepface][原创]使用deepface进行人脸检测


import cv2
import os
from deepface.detectors import FaceDetector

detector_backend = 'opencv'
face_detector = FaceDetector.build_model(detector_backend)
cap = cv2.VideoCapture(0)  # webcam
while True:
    ret, img = cap.read()
    if img is None:
        break
    try:
        # faces store list of detected_face and region pair
        faces = FaceDetector.detect_faces(face_detector, detector_backend, img, align=False)
    except:  # to avoid exception if no face detected
        faces = []
    for face, (x, y, w, h) in faces:
        if w > 130:  # discard small detected faces
            cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 3)  # draw rectangle to main image
    cv2.imshow('result', img)
    if cv2.waitKey(1) & 0xFF == ord('q'):  # press q to quit
        break
# kill open cv things
cap.release()
cv2.destroyAllWindows()

举报

相关推荐

0 条评论