Files
crumbmissions/snake_camera_vision_v2/gestures/gestures.py.v2
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.8 KiB
Plaintext
Executable File

import cv2
import numpy as np
def detect_hand_gesture(frame):
height, width, _ = frame.shape
# Dynamische ROI: Mitte des Bildes, zentriert
roi_w, roi_h = 200, 200
x_start = width // 2 - roi_w // 2
y_start = height // 2 - roi_h // 2
roi = frame[y_start:y_start + roi_h, x_start:x_start + roi_w]
# Zeichne das ROI-Fenster im Originalbild
cv2.rectangle(frame, (x_start, y_start), (x_start + roi_w, y_start + roi_h), (0, 255, 0), 2)
# Konvertiere zu HSV-Farbraum für bessere Hauterkennung
hsv = cv2.cvtColor(roi, cv2.COLOR_BGR2HSV)
# Hautfarbmaske (getestet für mittlere Hauttöne)
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)
# Glättung und Konturen finden
mask = cv2.GaussianBlur(mask, (5, 5), 0)
contours, _ = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
if contours:
# Größte Kontur annehmen
max_contour = max(contours, key=cv2.contourArea)
area = cv2.contourArea(max_contour)
if area > 2000:
# Konvexitätsdefekte (Finger) berechnen
hull = cv2.convexHull(max_contour, returnPoints=False)
if hull is not None and len(hull) > 3:
defects = cv2.convexityDefects(max_contour, hull)
finger_count = 0
if defects is not None:
for i in range(defects.shape[0]):
s, e, f, d = defects[i, 0]
if d > 10000:
finger_count += 1
if finger_count >= 3:
return "wave", roi
else:
return "fist", roi
return "none", roi