# 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)