当前位置:   article > 正文

【代码学习】Mediapipe人脸检测使用记录_mediapipe 五官

mediapipe 五官

Mediapipe,每秒200-300帧的实时人脸检测,提取画面中的人脸框,实现后续各种应用:人脸属性识别、表情识别、关键点检测、三维重建、增强现实、AI换妆等

code:google/mediapipe: Cross-platform, customizable ML solutions for live and streaming media. (github.com)

理论

  检测到的人脸集合,其中每个人脸都表示为一个检测原型消息,其中包含一个边界框和 6 个关键点(右眼、左眼、鼻尖、嘴巴中心、右耳和左耳)。边界框由xminwidth(均由[0.0, 1.0]图像宽度归一化)和ymin和(均由图像高度height归一化)组成。[0.0, 1.0]每个关键点由x和组成,分别由图像宽度和高度y归一化。[0.0, 1.0]

  1. import cv2
  2. import mediapipe as mp
  3. mp_face_detection = mp.solutions.face_detection
  4. mp_drawing = mp.solutions.drawing_utils
  5. # For webcam input:
  6. cap = cv2.VideoCapture(0)
  7. with mp_face_detection.FaceDetection(model_selection=0,
  8. min_detection_confidence=0.5) as face_detection:
  9. while cap.isOpened():
  10. success, image = cap.read()
  11. if not success:
  12. print("Ignoring empty camera frame.")
  13. # If loading a video, use 'break' instead of 'continue'.
  14. continue
  15. # To improve performance, optionally mark the image as not writeable to
  16. # pass by reference.
  17. image.flags.writeable = False
  18. image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
  19. results = face_detection.process(image)
  20. # Draw the face detection annotations on the image.
  21. image.flags.writeable = True
  22. image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
  23. if results.detections:
  24. for detection in results.detections:
  25. mp_drawing.draw_detection(image, detection)
  26. # Flip the image horizontally for a selfie-view display.
  27. cv2.imshow('MediaPipe Face Detection', cv2.flip(image, 1))
  28. if cv2.waitKey(5) & 0xFF == 27:
  29. break
  30. cap.release()
  31. 复制代码

468个人脸关键点:

 

Diffusion Video Editing

结合论文:Speech Driven Video Editing via an Audio-Conditioned Diffusion Model

video preprocess

每个视频帧需要有一个矩形区域的脸掩盖。使用mediapipe,提取面部landmark来确定颌骨的位置。使用这些信息,mask掉覆盖鼻子下方区域的脸部矩形部分,如图1所示。这个掩码是在数据加载器运行时计算并应用到帧上的。

参考:一起来学MediaPipe(一)人脸及五官定位检测-阿里云开发者社区 (aliyun.com)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小惠珠哦/article/detail/906110
推荐阅读
相关标签
  

闽ICP备14008679号