人脸识别的几种方法

HOG

import cv2
import dlib

cap = cv2.VideoCapture(0)

while(True):
    ret,img = cap.read()

    hog_face_detector = dlib.get_frontal_face_detector()
    detections = hog_face_detector(img,1)
    for face in detections:
        x = face.left()
        y = face.top()
        r = face.right()
        b = face.bottom()
        cv2.rectangle(img,(x,y),(r,b),(255,255,0),2)


    cv2.imshow("frame",img)

    if cv2.waitKey(1)&0xFF == ord("q"):
        break
cap.release()
cv2.destroyAllWindows()

CNN

import cv2
import dlib

cap = cv2.VideoCapture(0)

while(True):
    ret,img = cap.read()

    face_detector = dlib.cnn_face_detection_model_v1("./weights/mmod_human_face_detector.dat")
    detections = face_detector(img,1)
    for face in detections:
        x = face.rect.left()
        y = face.rect.top()
        r = face.rect.right()
        b = face.rect.bottom()
        cv2.rectangle(img,(x,y),(r,b),(255),2)


    cv2.imshow("frame",img)

    if cv2.waitKey(1)&0xFF == ord("q"):
        break
cap.release()
cv2.destroyAllWindows()

人脸关键点检测

import cv2
import dlib

cap = cv2.VideoCapture(0)

while(True):
    ret,img = cap.read()

    hog_face_detector = dlib.get_frontal_face_detector()
    face_detector = dlib.shape_predictor("./weights/shape_predictor_68_face_landmarks.dat")

    detections = hog_face_detector(img,1)
    for face in detections:
        x = face.left()
        y = face.top()
        r = face.right()
        b = face.bottom()
        points68 = face_detector(img,face)
        for point in points68.parts():
            cv2.circle(img,(point.x,point.y),2,(0,255,0),1)
        cv2.rectangle(img,(x,y),(r,b),(255),2)

    cv2.imshow("frame",img)

    if cv2.waitKey(1)&0xFF == ord("q"):
        break
cap.release()
cv2.destroyAllWindows()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值