可信网站的作用,德州最新通知,外贸平台补贴政策,重庆建设网站哪家专业✨博客主页#xff1a;王乐予#x1f388; ✨年轻人要#xff1a;Living for the moment#xff08;活在当下#xff09;#xff01;#x1f4aa; #x1f3c6;推荐专栏#xff1a;【图像处理】【千锤百炼Python】【深度学习】【排序算法】 目录 #x1f63a;一、Med… ✨博客主页王乐予 ✨年轻人要Living for the moment活在当下 推荐专栏【图像处理】【千锤百炼Python】【深度学习】【排序算法】 目录 一、MediaPipe概述二、MediaPipe人脸检测概述三、程序实现四、检测结果 一、MediaPipe概述
MediaPipe 是一款由 Google Research 开发并开源的多媒体机器学习模型应用框架。
MediaPipe目前支持的解决方案(Solution)及支持的平台如下图所示
二、MediaPipe人脸检测概述
MediaPipe 人脸检测器可以检测图片或视频中的人脸。可以使用此任务在帧中定位人脸和面部特征。此任务使用可处理单张图片或连续图片流的机器学习 (ML) 模型。该任务会输出人脸位置以及以下面部关键点左眼、右眼、鼻尖、嘴巴、左眼区域和右眼区域。
MediaPipe人脸检测所用模型是BlazeFace的变体BlazeFace 是谷歌19年提出的一种针对移动 GPU 推断进行优化的轻量级且精确的人脸检测器。 BlazeFace: Sub-millisecond Neural Face Detection on Mobile GPUs 三、程序实现
import cv2
import mediapipe as mpmp_face_detection mp.solutions.face_detection
face_detection mp_face_detection.FaceDetection(min_detection_confidence0.5, model_selection1)cap cv2.VideoCapture(../test.mp4)while cap.isOpened():success, image cap.read()# Convert color space because MediaPipe requires images in RGB formatimage cv2.cvtColor(cv2.flip(image, 1), cv2.COLOR_BGR2RGB)# Perform facial detectionresults face_detection.process(image)# Convert back to BGR so that OpenCV can display imagesimage cv2.cvtColor(image, cv2.COLOR_RGB2BGR)# Draw detected facial bounding boxesif results.detections:for detection in results.detections:mp_drawing mp.solutions.drawing_utilsmp_drawing.draw_detection(image, detection, mp_drawing.DrawingSpec(thickness4, circle_radius2, color(48, 255, 159)))cv2.imshow(MediaPipe Face Detection, image)if cv2.waitKey(1) 0xFF ord(q):breakcap.release()
cv2.destroyAllWindows()四、检测结果