cv-mediapipe
Context: $ARGUMENTS
Google MediaPipe Tasks API (mediapipe.tasks.python.*). Every Task in MediaPipe follows the same four-step shape: BaseOptions → <Task>Options → <Task>.create_from_options → detect/classify/recognize/generate. Docs home: https://ai.google.dev/edge/mediapipe/solutions/guide.
Critical gotcha — which MediaPipe?
MediaPipe has TWO Python APIs. Always use the new one.
| API | Status | Import |
|-----------------------------------|----------------|------------------------------------------|
| mediapipe.solutions.* (legacy) | DEPRECATED | from mediapipe.solutions import pose |
| mediapipe.tasks.python.* (Tasks)| CURRENT | from mediapipe.tasks.python import vision |
Never recommend the legacy solutions API for new work. The Tasks API has strictly more features (run modes, model hot-swap, explicit timestamps) and is the one Google ships updates for.
Quick start
- Face landmarks (478 points + blendshapes): → Step 3 (
mp.py face-landmark) - Hand landmarks (21 points / hand): → Step 3 (
mp.py hand-landmark) - Pose landmarks (33 points, 3D): → Step 3 (
mp.py pose-landmark) - Generic object detection: → Step 3 (
mp.py object-detect) - Selfie or interactive segmentation: → Step 3 (
mp.py segment) - Gesture classification: → Step 3 (
mp.py gesture) - Audio event classification: → Step 3 (
mp.py audio-classify) - Text classification / embedding / language-detect: → Step 3 (
mp.py text-*) - On-device LLM inference (Gemma / Phi-2): → Step 4 (
mp.py llm)
When to use
- Fast, portable, pre-trained vision models for faces, hands, bodies, gestures, segmentation — on CPU, no PyTorch/TF required.
- Mobile or embedded targets (Android, iOS, Raspberry Pi) — MediaPipe is the canonical Google stack there.
- Pair with
cv-opencvfor I/O + classical CV; MediaPipe hands you landmark/bbox tensors, OpenCV draws / saves / captures.
For custom ONNX models, use cv-opencv dnn module or a full framework instead. Use MediaPipe only when its pre-trained Tasks fit your need.
Step 1 — Install
pip install 'mediapipe>=0.10.14' opencv-python numpy
Or via the helper's PEP 723 header: uv run scripts/mp.py ... handles the venv + deps automatically.
The required wheel is plain mediapipe. mediapipe-silicon and mediapipe-rpi forks predate the current release cadence; prefer the upstream wheel.
Step 2 — Download the Task bundle (`.task` file)
Every Vision Task loads from a single .task file (a Zip bundle with models + metadata). Canonical models are listed on each Task page under ai.google.dev/edge/mediapipe/solutions/vision/<task>/#models.
Commonly used bundles:
| Task | Filename | URL prefix |
|---------------------|----------------------------------------------------|---------------------------------------------------------------------|
| Face Detector | blaze_face_short_range.tflite | https://storage.googleapis.com/mediapipe-models/face_detector/... |
| Face Landmarker | face_landmarker.task | https://storage.googleapis.com/mediapipe-models/face_landmarker/... |
| Hand Landmarker | hand_landmarker.task | https://storage.googleapis.com/mediapipe-models/hand_landmarker/... |
| Pose Landmarker | pose_landmarker_lite.task (or _full, _heavy) | https://storage.googleapis.com/mediapipe-models/pose_landmarker/... |
| Gesture Recognizer | gesture_recognizer.task | https://storage.googleapis.com/mediapipe-models/gesture_recognizer/... |
| Object Detector | efficientdet_lite0.tflite | https://storage.googleapis.com/mediapipe-models/object_detector/... |
| Image Classifier | efficientnet_lite0.tflite | https://storage.googleapis.com/mediapipe-models/image_classifier/... |
| Image Segmenter | selfie_segmenter.tflite | https://storage.googleapis.com/mediapipe-models/image_segmenter/... |
| Audio Classifier | yamnet.tflite | https://storage.googleapis.com/mediapipe-models/audio_classifier/... |
| Text Classifier | bert_classifier.tflite | https://storage.googleapis.com/mediapipe-models/text_classifier/... |
| LLM Inference | gemma-2b-it-cpu-int4.bin etc. | Kaggle / HuggingFace (see Step 4) |