Commit ·
585e14d
1
Parent(s): ac24fdc
手势识别: 移除自动安装,无mediapipe时静默禁用
Browse files
reachy_mini_ha_voice/gesture_detector.py
CHANGED
|
@@ -13,15 +13,16 @@ Detects 11 hand gestures for robot interaction:
|
|
| 13 |
- three: 3️⃣ Three fingers
|
| 14 |
- four: 4️⃣ Four fingers
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
"""
|
| 19 |
|
| 20 |
from __future__ import annotations
|
| 21 |
import logging
|
| 22 |
-
import platform
|
| 23 |
-
import subprocess
|
| 24 |
-
import sys
|
| 25 |
from enum import Enum
|
| 26 |
from typing import Optional, Tuple, Callable
|
| 27 |
import time
|
|
@@ -32,42 +33,7 @@ from numpy.typing import NDArray
|
|
| 32 |
logger = logging.getLogger(__name__)
|
| 33 |
|
| 34 |
|
| 35 |
-
|
| 36 |
-
"""Try to install mediapipe for the current platform."""
|
| 37 |
-
arch = platform.machine().lower()
|
| 38 |
-
|
| 39 |
-
if arch in ('aarch64', 'arm64'):
|
| 40 |
-
# ARM64: install older version without deps to avoid numpy conflict
|
| 41 |
-
logger.info("ARM64 detected, installing mediapipe 0.10.18...")
|
| 42 |
-
try:
|
| 43 |
-
subprocess.check_call([
|
| 44 |
-
sys.executable, '-m', 'pip', 'install',
|
| 45 |
-
'mediapipe==0.10.18', '--no-deps', '-q'
|
| 46 |
-
])
|
| 47 |
-
# Install required deps that don't conflict
|
| 48 |
-
subprocess.check_call([
|
| 49 |
-
sys.executable, '-m', 'pip', 'install',
|
| 50 |
-
'flatbuffers>=2.0', 'absl-py', '-q'
|
| 51 |
-
])
|
| 52 |
-
return True
|
| 53 |
-
except subprocess.CalledProcessError as e:
|
| 54 |
-
logger.warning("Failed to install mediapipe: %s", e)
|
| 55 |
-
return False
|
| 56 |
-
else:
|
| 57 |
-
# x86_64: install latest version
|
| 58 |
-
logger.info("x86_64 detected, installing mediapipe...")
|
| 59 |
-
try:
|
| 60 |
-
subprocess.check_call([
|
| 61 |
-
sys.executable, '-m', 'pip', 'install',
|
| 62 |
-
'mediapipe>=0.10.31', '-q'
|
| 63 |
-
])
|
| 64 |
-
return True
|
| 65 |
-
except subprocess.CalledProcessError as e:
|
| 66 |
-
logger.warning("Failed to install mediapipe: %s", e)
|
| 67 |
-
return False
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
# Try to import mediapipe
|
| 71 |
_mp_hands = None
|
| 72 |
_mediapipe_available = False
|
| 73 |
|
|
@@ -75,19 +41,11 @@ try:
|
|
| 75 |
import mediapipe as mp
|
| 76 |
_mp_hands = mp.solutions.hands
|
| 77 |
_mediapipe_available = True
|
| 78 |
-
logger.info("MediaPipe loaded
|
| 79 |
except ImportError:
|
| 80 |
-
logger.info("MediaPipe not
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
import mediapipe as mp
|
| 84 |
-
_mp_hands = mp.solutions.hands
|
| 85 |
-
_mediapipe_available = True
|
| 86 |
-
logger.info("MediaPipe installed and loaded successfully")
|
| 87 |
-
except ImportError as e:
|
| 88 |
-
logger.warning("MediaPipe import failed after install: %s", e)
|
| 89 |
-
else:
|
| 90 |
-
logger.warning("Gesture detection disabled - mediapipe unavailable")
|
| 91 |
|
| 92 |
|
| 93 |
class Gesture(Enum):
|
|
@@ -144,9 +102,7 @@ class GestureDetector:
|
|
| 144 |
self._available = True
|
| 145 |
logger.info("MediaPipe Hands initialized")
|
| 146 |
except Exception as e:
|
| 147 |
-
logger.
|
| 148 |
-
else:
|
| 149 |
-
logger.warning("Gesture detection disabled - MediaPipe not available")
|
| 150 |
|
| 151 |
@property
|
| 152 |
def is_available(self) -> bool:
|
|
|
|
| 13 |
- three: 3️⃣ Three fingers
|
| 14 |
- four: 4️⃣ Four fingers
|
| 15 |
|
| 16 |
+
Requires mediapipe to be pre-installed. If not available, gesture detection
|
| 17 |
+
is silently disabled (no network installation attempts).
|
| 18 |
+
|
| 19 |
+
For ARM64 (Raspberry Pi), install manually:
|
| 20 |
+
pip install mediapipe==0.10.18 --no-deps
|
| 21 |
+
pip install flatbuffers absl-py
|
| 22 |
"""
|
| 23 |
|
| 24 |
from __future__ import annotations
|
| 25 |
import logging
|
|
|
|
|
|
|
|
|
|
| 26 |
from enum import Enum
|
| 27 |
from typing import Optional, Tuple, Callable
|
| 28 |
import time
|
|
|
|
| 33 |
logger = logging.getLogger(__name__)
|
| 34 |
|
| 35 |
|
| 36 |
+
# Try to import mediapipe (no auto-install to avoid network issues)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
_mp_hands = None
|
| 38 |
_mediapipe_available = False
|
| 39 |
|
|
|
|
| 41 |
import mediapipe as mp
|
| 42 |
_mp_hands = mp.solutions.hands
|
| 43 |
_mediapipe_available = True
|
| 44 |
+
logger.info("MediaPipe loaded for gesture detection")
|
| 45 |
except ImportError:
|
| 46 |
+
logger.info("MediaPipe not installed - gesture detection disabled")
|
| 47 |
+
except Exception as e:
|
| 48 |
+
logger.warning("MediaPipe load error: %s - gesture detection disabled", e)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
|
| 51 |
class Gesture(Enum):
|
|
|
|
| 102 |
self._available = True
|
| 103 |
logger.info("MediaPipe Hands initialized")
|
| 104 |
except Exception as e:
|
| 105 |
+
logger.warning("Failed to initialize MediaPipe Hands: %s", e)
|
|
|
|
|
|
|
| 106 |
|
| 107 |
@property
|
| 108 |
def is_available(self) -> bool:
|