import cv2 import streamlit as st import mediapipe as mp import time # Mediapipe init mp_hands = mp.solutions.hands mp_draw = mp.solutions.drawing_utils def process_frame(frame, hands): frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) results = hands.process(frame_rgb) if results.multi_hand_landmarks: for hand_landmarks in results.multi_hand_landmarks: mp_draw.draw_landmarks(frame, hand_landmarks, mp_hands.HAND_CONNECTIONS) return frame st.title("🤚 Live Hand Gesture Tracking (Local Webcam Only)") run = st.checkbox("Start Webcam") FRAME_WINDOW = st.empty() cap = cv2.VideoCapture(0) with mp_hands.Hands( static_image_mode=False, max_num_hands=2, min_detection_confidence=0.7, min_tracking_confidence=0.7 ) as hands: while run: ret, frame = cap.read() if not ret: st.warning("⚠️ Failed to grab frame. Try another camera index (0,1,2).") break frame = cv2.flip(frame, 1) frame = process_frame(frame, hands) FRAME_WINDOW.image(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB), channels="RGB") time.sleep(0.03) # smooth refresh cap.release()