
除了手势识别追踪和人脸的“面部网格”识别之外,MediaPipe 还能实现“姿势侦测”(Pose,又称“姿态识别”),它将人体模型标注出0-32 共33 个关键点,比如6对应的是右眼外眼角(right_eye_outer)、13 对应的是左肘尖(left_elbow)、30 对应的是右脚跟(right_heel)等等。头部的关键点是从0到10,身体的左侧关键点是奇数从11、13 直至31,右侧是偶数从12、14 直至32,二者所对应的身体部位是对称标注的(如图)。
1.对静态图像文件中的人体进行姿势侦测
首先, 导入OpenCV 和MediaPipe 库模块:“importcv2”“import mediapipe asmp”;然后进行人体姿势侦测模型的导入——建立变量mp_pose 并赋值为“mp.solutions.pose”;再建立变量mp_drawing,赋值为“mp.solutions.drawing_utils”,作用是导入绘图模块;建立姿势侦测变量pose,赋值为“mp_pose.Pose(static_image_mode=True,model_complexity=2, smooth_l a n d m a r k s = T r u e , e n a b l e _s e g m e n t a t i o n = T r u e , m i n _detection_confidence=0.5,min_tracking_confidence=0.5)”,其中的参数“static_image_mode=True” 作用是设置为静态图像文件的检测, 参数“model_complexity=2” 作用是设置为最佳的姿势侦测(值为0 时速度最快但 性能较弱,值为1 时速度与性能比较均衡), 参数“smooth_landmarks=True” 作用是将平滑关键点的检测设置为有效,参数“enable_segmentation=True”作用是将人体抠图设置为有效, 参数“min_detection_confidence=0.5” 和“min_tracking_confidence=0.5)”作用是分别设置侦测的置信度与追踪阈值。

