import cv2 import mediapipe as mp import numpy as np def detect_batter_pose(frame): mp_pose = mp.solutions.pose with mp_pose.Pose(static_image_mode=True) as pose: results = pose.process(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)) return results.pose_landmarks if results.pose_landmarks else None def is_pad_contact(ball_xy, landmarks, width, height): if not landmarks: return False knees = [25, 26] for i in knees: px = int(landmarks[i].x * width) py = int(landmarks[i].y * height) if np.linalg.norm(np.array([px, py]) - np.array(ball_xy)) < 50: return True return False