Files
crumbmissions/snake_camera_vision_v2/gestures/gestures_debug.py
Branko May Trinkwald 2915828adf Add complete Crumbforest mission system
- Interactive mission selector with metadata-driven design
- 5 educational missions (basics + advanced)
- AI assistant roles (Deepbit, Bugsy, Schnippsi, Tobi)
- SnakeCam gesture recognition system
- Token tracking utilities
- CLAUDE.md documentation
- .gitignore for logs and secrets
2025-12-21 01:16:48 +01:00

51 lines
1.6 KiB
Python
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# gestures_debug.py
import cv2
import numpy as np
def detect_hand_gesture(frame):
height, width, _ = frame.shape
# --- Fallback-ROI: Mitte des Bildes ---
w, h = 100, 100
x = width // 2 - w // 2
y = height // 2 - h // 2
roi = frame[y:y+h, x:x+w]
if roi.size == 0:
print("[warn] ROI leer kein Bildausschnitt verarbeitet")
return "none", (x, y, w, h)
hsv = cv2.cvtColor(roi, cv2.COLOR_BGR2HSV)
lower_skin = np.array([0, 20, 70], dtype=np.uint8)
upper_skin = np.array([20, 255, 255], dtype=np.uint8)
mask = cv2.inRange(hsv, lower_skin, upper_skin)
mask = cv2.dilate(mask, np.ones((3, 3), np.uint8), iterations=4)
mask = cv2.GaussianBlur(mask, (5, 5), 100)
contours, _ = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
gesture = "none"
if contours and len(contours) > 0:
max_contour = max(contours, key=cv2.contourArea)
hull = cv2.convexHull(max_contour, returnPoints=False)
if hull is not None and len(hull) > 3:
defects = cv2.convexityDefects(max_contour, hull)
if defects is not None:
cnt_defects = defects.shape[0]
if cnt_defects >= 4:
gesture = "wave"
elif cnt_defects <= 1:
gesture = "fist"
else:
gesture = "unknown"
print(f"[debug] Defekte: {len(defects) if defects is not None else 'None'}")
else:
print("[debug] Keine Konturen erkannt")
print(f"[result] Geste erkannt: {gesture}")
return gesture, (x, y, w, h)