MediaPipe 是由 Google 開發的開源跨平台機器學習框架,專為即時和串流媒體處理而設計。它提供了一套完整的工具和函式庫,讓開發者能夠輕鬆地在各種平台上部署和客製化機器學習解決方案。
項目地址: https://github.com/google-ai-edge/mediapipe
MediaPipe 提供了多種預訓練的機器學習模型,包括:
現代化的高級 API,提供:
底層框架組件,用於構建自定義的機器學習管道:
pip install mediapipe
npm install @mediapipe/tasks-vision
import mediapipe as mp
import cv2
# 初始化手部檢測
mp_hands = mp.solutions.hands
hands = mp_hands.Hands()
# 處理影片幀
cap = cv2.VideoCapture(0)
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
# 檢測手部
results = hands.process(frame)
# 繪製結果
if results.multi_hand_landmarks:
for hand_landmarks in results.multi_hand_landmarks:
mp.solutions.drawing_utils.draw_landmarks(
frame, hand_landmarks, mp_hands.HAND_CONNECTIONS)
cv2.imshow('MediaPipe Hands', frame)
if cv2.waitKey(5) & 0xFF == 27:
break
cap.release()
cv2.destroyAllWindows()
MediaPipe 是一個功能強大、易於使用的機器學習框架,特別適合需要即時 AI 功能的應用開發。它的跨平台特性、高效能表現和豐富的預訓練模型使其成為開發者構建智能應用的理想選擇。無論是初學者還是經驗豐富的開發者,都能透過 MediaPipe 快速實現複雜的機器學習功能。