mtcnn人脸检测(python)

import mtcnn  # pip install mtcnn
import cv2 as cv

def detect():
    camera = cv.VideoCapture(0)
    detect = mtcnn.MTCNN()  # 调用mtcnn
    while True:
        success, frame = camera.read()  # 读取每一帧
        frame = cv.flip(frame,1)
        if success != True:
            break
        face = detect.detect_faces(frame)  # 人脸检测
        for item in face:  # 遍历
            if item['confidence'] < 0.9:  # 设置阈值
                continue
            box = item['box']
            cv.rectangle(frame, (box[0], box[1]), (box[0] + box[2], box[1] + box[3]), (255, 0, 0), 2)  # 绘制矩形
            points = item['keypoints']  # 绘制关键点
            cv.circle(frame, points['left_eye'], 2, (255, 0, 0),3)
            cv.circle(frame, points['right_eye'], 2, (255, 0, 0),3)
            cv.circle(frame, points['nose'], 2, (255, 0, 0),3)
            cv.circle(frame, points['mouth_left'], 2, (255, 0, 0),3)
            cv.circle(frame, points['mouth_right'], 2, (255, 0, 0),3)
            confidence = item['confidence']
            cv.putText(frame, '{}'.format(confidence), (box[0], box[1] - 10), cv.FONT_HERSHEY_SIMPLEX, 1, (255, 0, 0), 2)
        cv.imshow("frame", frame)  # 显示
        if cv.waitKey(1) & 0xFF == ord(" "):
            break

    camera.release()
    cv.destroyAllWindows()

if __name__ == "__main__":
    detect()

参考文献:https://blog.csdn.net/qq_34108714/article/details/90789288

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值