Piyush23890/Sign_Language_Decoder
0
1"""2hand_landmarks.py3=================4Simple webcam viewer that draws MediaPipe hand landmarks and5labels each detected hand as "Left" or "Right".6 7Useful for verifying your camera works before running the full app.8 9Usage10-----11 python hand_landmarks.py12 13Press ESC to quit.14"""15 16import cv217import mediapipe as mp18 19mp_hands = mp.solutions.hands20mp_draw = mp.solutions.drawing_utils21 22hands = mp_hands.Hands(23 static_image_mode=False,24 max_num_hands=2,25 min_detection_confidence=0.70,26 min_tracking_confidence=0.70,27)28 29cap = cv2.VideoCapture(0)30print("Hand landmark viewer — press ESC to quit.")31 32while True:33 ok, frame = cap.read()34 if not ok:35 break36 37 frame = cv2.flip(frame, 1)38 rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)39 res = hands.process(rgb)40 41 if res.multi_hand_landmarks:42 for idx, hl in enumerate(res.multi_hand_landmarks):43 mp_draw.draw_landmarks(44 frame, hl, mp_hands.HAND_CONNECTIONS,45 mp_draw.DrawingSpec(color=(0, 255, 0), thickness=2, circle_radius=4),46 mp_draw.DrawingSpec(color=(255, 0, 0), thickness=2),47 )48 # Label Left / Right at wrist position49 label = res.multi_handedness[idx].classification[0].label50 wrist = hl.landmark[0]51 h, w = frame.shape[:2]52 cx, cy= int(wrist.x * w), int(wrist.y * h)53 cv2.putText(frame, label,54 (cx - 35, cy - 22),55 cv2.FONT_HERSHEY_SIMPLEX, 0.85,56 (255, 255, 255), 2)57 58 # FPS hint59 cv2.putText(frame, "ESC to quit",60 (10, 28), cv2.FONT_HERSHEY_SIMPLEX,61 0.65, (180, 180, 180), 1)62 cv2.imshow("Hand Landmarks — SignBridge", frame)63 64 if cv2.waitKey(1) & 0xFF == 27:65 break66 67cap.release()68cv2.destroyAllWindows()69 