tomrikert commited on
Commit ·
1607ad8
1
Parent(s): c8c58de
Add EMA smoothing to face tracking to reduce jitter
Browse files
src/reachy_mini_openclaw/camera_worker.py
CHANGED
|
@@ -63,6 +63,13 @@ class CameraWorker:
|
|
| 63 |
|
| 64 |
# Tracking scale factor (adjust responsiveness)
|
| 65 |
self.tracking_scale = 0.6 # Scale down movements for smoother tracking
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
def get_latest_frame(self) -> Optional[NDArray[np.uint8]]:
|
| 68 |
"""Get the latest frame (thread-safe).
|
|
@@ -203,12 +210,23 @@ class CameraWorker:
|
|
| 203 |
translation *= self.tracking_scale
|
| 204 |
rotation *= self.tracking_scale
|
| 205 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
# Thread-safe update of face tracking offsets
|
| 207 |
with self.face_tracking_lock:
|
| 208 |
-
self.face_tracking_offsets =
|
| 209 |
-
translation[0], translation[1], translation[2],
|
| 210 |
-
rotation[0], rotation[1], rotation[2],
|
| 211 |
-
]
|
| 212 |
|
| 213 |
else:
|
| 214 |
# No face detected - handle smooth interpolation back to neutral
|
|
|
|
| 63 |
|
| 64 |
# Tracking scale factor (adjust responsiveness)
|
| 65 |
self.tracking_scale = 0.6 # Scale down movements for smoother tracking
|
| 66 |
+
|
| 67 |
+
# Smoothing factor for exponential moving average (0.0-1.0)
|
| 68 |
+
# Lower = smoother but slower response, Higher = faster but more jitter
|
| 69 |
+
self.smoothing_alpha = 0.15 # Smooth out jitter from detection noise
|
| 70 |
+
|
| 71 |
+
# Previous smoothed offsets for EMA calculation
|
| 72 |
+
self._smoothed_offsets: List[float] = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
|
| 73 |
|
| 74 |
def get_latest_frame(self) -> Optional[NDArray[np.uint8]]:
|
| 75 |
"""Get the latest frame (thread-safe).
|
|
|
|
| 210 |
translation *= self.tracking_scale
|
| 211 |
rotation *= self.tracking_scale
|
| 212 |
|
| 213 |
+
# Apply exponential moving average (EMA) smoothing to reduce jitter
|
| 214 |
+
# new_smoothed = alpha * new_value + (1 - alpha) * old_smoothed
|
| 215 |
+
alpha = self.smoothing_alpha
|
| 216 |
+
new_offsets = [
|
| 217 |
+
translation[0], translation[1], translation[2],
|
| 218 |
+
rotation[0], rotation[1], rotation[2],
|
| 219 |
+
]
|
| 220 |
+
|
| 221 |
+
smoothed = [
|
| 222 |
+
alpha * new_offsets[i] + (1 - alpha) * self._smoothed_offsets[i]
|
| 223 |
+
for i in range(6)
|
| 224 |
+
]
|
| 225 |
+
self._smoothed_offsets = smoothed
|
| 226 |
+
|
| 227 |
# Thread-safe update of face tracking offsets
|
| 228 |
with self.face_tracking_lock:
|
| 229 |
+
self.face_tracking_offsets = smoothed
|
|
|
|
|
|
|
|
|
|
| 230 |
|
| 231 |
else:
|
| 232 |
# No face detected - handle smooth interpolation back to neutral
|