使用mediapipe进行人脸识别

import cv2
import mediapipe as mp
import time

cap = cv2.VideoCapture('C:/Users/Curry\Desktop/Kobe.mp4',0)

mpFace_dec = mp.solutions.face_detection
mpdraw = mp.solutions.drawing_utils
face_dec = mpFace_dec.FaceDetection(0.75)

Pre_time = 0
while 1:
    res, img = cap.read()
    img_rgb = cv2.cvtColor(img, code=cv2.COLOR_BGR2RGB)
    Results = face_dec.process(img_rgb)
    # print(Results)
    if Results.detections:
        for id, detection in enumerate(Results.detections):
            # mpdraw.draw_detection(img, detection)
            # print(id, detection)
            # print(detection.score)
            # print(detection.location_data.relative_bounding_box)
            bboxC = detection.location_data.relative_bounding_box
            h,w,c = img.shape
            bbox = int(bboxC.xmin*w),int(bboxC.ymin*h),\
                       int(bboxC.width*w),int(bboxC.height*h)
            cv2.rectangle(img, bbox, (255, 0, 255), 2)

    cur_Time = time.time()
    fps = 1/(cur_Time-Pre_time)
    Pre_time = cur_Time
    cv2.putText(img, 'FPS:{}'.format(int(fps)), (20, 70),
                cv2.FONT_HERSHEY_PLAIN, 3, (0, 0, 255), 2)
    cv2.imshow('kobe', img)
    cv2.waitKey(1)



import cv2
import mediapipe as mp
import time

cap = cv2.VideoCapture('C:/Users/Curry\Desktop/kobe.mp4',0)

mpFace_dec = mp.solutions.face_detection
mpdraw = mp.solutions.drawing_utils
face_dec = mpFace_dec.FaceDetection(0.75)

Pre_time = 0
while 1:
    res, img = cap.read()
    img_rgb = cv2.cvtColor(img, code=cv2.COLOR_BGR2RGB)
    Results = face_dec.process(img_rgb)
    # print(Results)
    if Results.detections:
        for id, detection in enumerate(Results.detections):
            # mpdraw.draw_detection(img, detection)
            # print(id, detection)
            # print(detection.score)
            # print(detection.location_data.relative_bounding_box)
            bboxC = detection.location_data.relative_bounding_box
            h,w,c = img.shape
            bbox = int(bboxC.xmin * w), int(bboxC.ymin * h), \
                   int(bboxC.width * w), int(bboxC.height * h)
            cv2.rectangle(img, bbox, (255, 0, 255), 2)
            cv2.putText(img, f'{int(detection.score[0]*100)}%',(bbox[0],bbox[1]-20),
                    cv2.FONT_HERSHEY_PLAIN,2,(255, 0, 255), 2)

    cur_Time = time.time()
    fps = 1/(cur_Time-Pre_time)
    Pre_time = cur_Time
    cv2.putText(img, 'FPS:{}'.format(int(fps)), (20, 70),
                cv2.FONT_HERSHEY_PLAIN, 3, (0, 0, 255), 2)
    cv2.imshow('kobe', img)
    cv2.waitKey(1)



评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

青葱岁月夏小凡

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值