Files
crumbmissions/snake_camera_vision_v2/gestures/gestures_v4.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

40 lines
1.3 KiB
Python
Executable File

import cv2
import numpy as np
def detect_hand_gesture(frame):
x, y, w, h = 100, 100, 150, 150
roi = frame[y:y+h, x:x+w]
hsv = cv2.cvtColor(roi, cv2.COLOR_BGR2HSV)
# einfache Hautfarbe (hell bis leicht gebräunt)
lower_skin = np.array([0, 30, 60], dtype=np.uint8)
upper_skin = np.array([20, 150, 255], dtype=np.uint8)
mask = cv2.inRange(hsv, lower_skin, upper_skin)
mask = cv2.GaussianBlur(mask, (5, 5), 0)
contours, _ = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
gesture = "none"
if contours:
contour = max(contours, key=cv2.contourArea)
area = cv2.contourArea(contour)
if area > 2500:
hull = cv2.convexHull(contour, returnPoints=False)
if hull is not None and len(hull) > 3:
defects = cv2.convexityDefects(contour, hull)
if defects is not None:
defect_count = defects.shape[0]
ratio = float(w) / h
print(f"[debug] Defekte: {defect_count}, Fläche: {int(area)}, Ratio: {ratio:.2f}")
# 🌊 einfache Regel für Winken
if 3 <= defect_count <= 10 and 2000 < area < 15000 and 1.3 < ratio < 2.3:
gesture = "wave"
return gesture, (x, y, w, h)