mediapipe

midiapipe是一个实时计算机视觉框架

  1. 能够高效处理 手势识别、姿态估计、物体检测、语音处理 等任务
  2. 用计算图进行数据处理
  3. 预训练模型有这些:
    1. 手部跟踪 MediaPipe Hands
    2. 人体姿势估计 MediaPipe Pose
    3. 面部检测 MediaPipe Face Detection
    4. 面部网格 MediaPipe Face Mesh
    5. 物体检测 MediaPipe Objectron语音处理 MediaPipe Audio

主要看手部跟踪部分

MediaPipe Hands 是一个 高效的手部关键点检测模型,可检测 21 个关键点,用于手势识别。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import cv2
import mediapipe as mp

mp_hands = mp.solutions.hands
mp_draw = mp.solutions.drawing_utils
hands = mp_hands.Hands()

cap = cv2.VideoCapture(0)

while cap.isOpened():
success, frame = cap.read()
if not success:
continue

frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
results = hands.process(frame_rgb)

if results.multi_hand_landmarks:
for hand_landmarks in results.multi_hand_landmarks:
mp_draw.draw_landmarks(frame, hand_landmarks, mp_hands.HAND_CONNECTIONS)

cv2.imshow('MediaPipe Hands', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break

cap.release()
cv2.destroyAllWindows()