本帖最后由 一路向北lm 于 2025-4-3 16:37 编辑
Mediapipe 是一个开源的跨平台框架,它提供了大量的解决方案,用于构建高性能、跨平台的计算机视觉应用。Mediapipe 使用计算图(Calculation Graph)来表示算法的执行流程,可以轻松地组合和扩展不同的算法模块。板卡出厂的demo中展示的就是mediapipe的姿态检测。
人脸检测
mp_face_detection = mp.solutions.face_detection
# 创建 FaceDetection 类实例
face_detection = mp_face_detection.FaceDetection()
# 读取图像
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# 检测图像中的人脸
results = face_detection.process(img_rgb)
# 绘制人脸矩形框
if results.detections:
for detection in results.detections:
mp_drawing.draw_detection(img, detection)<span style="color: rgb(25, 27, 31); font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "PingFang SC", "Microsoft YaHei", "Source Han Sans SC", "Noto Sans CJK SC", "WenQuanYi Micro Hei", sans-serif; font-size: 1.1em; background-color: rgb(255, 255, 255);">手势识别</span>
手势识别
mp_hands = mp.solutions.hands
# 创建 Hand 类实例
hands = mp_hands.Hands()
# 读取图像
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# 处理图像
results = hands.process(img_rgb)
# 绘制手势关键点
if results.multi_hand_landmarks:
for hand_landmarks in results.multi_hand_landmarks:
mp_drawing.draw_landmarks(
img,
hand_landmarks,
mp_hands.HAND_CONNECTIONS,
)
姿态估计
mp_pose = mp.solutions.pose
# 创建 Pose 类实例
pose = mp_pose.Pose()
# 读取图像
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# 处理图像
results = pose.process(img_rgb)
# 绘制姿态关键点
if results.pose_landmarks:
mp_drawing.draw_landmarks(
img,
results.pose_landmarks,
mp_pose.POSE_CONNECTIONS,
)
|