A Python-based computer vision system that automatically counts football kick-ups by detecting ball-foot contact using pose estimation and object detection. The system provides real time visualization with distance tracking and kick counting.
Demo Post: Click here to watch the demo
This project provides tools to:
- Real time Ball Detection: Uses YOLOv11 to detect and track a sports ball in video
- Human Pose Estimation: Detects body keypoints using cvzone's PoseDetector
- Contact Detection: Calculates distance between ball and foot landmarks to detect kicks
- Automatic Counting: Counts kick-ups with configurable contact threshold and cooldown
- Live Visualization: Real time distance plotting and kick counter display
- Contact Feedback: Visual indicators showing when ball-foot contact is detected
- Automatic Kick Detection: No manual counting required
- Configurable Parameters: Adjust contact threshold and cooldown timing
- Real time Distance Tracking: Live plot showing ball-to-foot distance
- Visual Feedback: Color-coded indicators for contact detection
- Cooldown System: Prevents double-counting rapid successive contacts
- Resizable Display: Adjustable window for different screen sizes
git clone https://github.com/donsolo-khalifa/Kickups.git
cd Kickupspip install -r requirements.txtRequired packages:
opencv-python
mediapipe
cvzone
ultralytics
numpy
- Prepare your video: Place your kick-up video file in the project directory
- Update video path: Modify
VIDEO_PATHin the script to point to your video - Run the counter:
python main.py
- View results: The system will display real time kick counting and distance tracking
- Exit: Press 'q' to quit and see final count
# Contact Detection Parameters
CONTACT_THRESHOLD = 70 # Distance in pixels to trigger kick detection
COOLDOWN_FRAMES = 13 # Frames to wait before counting another kick
# Detection Landmarks
CONTACT_LANDMARKS = [31, 32] # Foot keypoints (left, right)
# Video Settings
VIDEO_PATH = 'vidb.mp4' # Path to your video file
YOLO_WEIGHTS = 'yolo11x.pt' # YOLO model weights- Contact Threshold: Adjust
CONTACT_THRESHOLDfor different ball sizes or detection sensitivity - Cooldown Period: Modify
COOLDOWN_FRAMESto prevent double counting - Contact Points: Change
CONTACT_LANDMARKSto use different body parts:[25, 26]- Knees[27, 28]- Ankles[31, 32]- Foot (default)[25, 26, 27, 28, 29, 30 31, 32]- Knees, Ankles, Foot and Heels (unstable)
- Video Source: Use
cv2.VideoCapture(0)for webcam input
- 'q': Quit the application
- Window Resize: Drag window corners to adjust size
- Frame Processing: Each video frame is processed for pose and object detection
- Ball Detection: YOLOv11 identifies and tracks the sports ball (COCO class 32)
- Pose Estimation: cvzone PoseDetector finds 33 body landmarks
- Distance Calculation: Measures distance between ball center and specified body landmarks
- Contact Detection: Triggers kick count when distance falls below threshold
- Cooldown Management: Prevents immediate re counting using frame based cooldown
- Green Circle: Ball detection indicator
- Yellow Lines: Distance measurement lines between ball and contact points
- Distance Plot: Real time graph showing ball-to-foot distance
- Green: During cooldown period (kick recently detected)
- Red: Normal tracking mode
- Kick Counter: Large text display showing current count
The system provides:
- Real time kick counting displayed on screen
- Distance visualization with live plotting
- Final count printed to console when video ends
- Visual feedback for contact detection events
- Model Size: YOLOv11x provides high accuracy but slower processing. Use smaller variants (n, s, m, l) for better performance
- Video Resolution: Higher resolution videos provide better detection but slower processing
- Contact Threshold: Lower values increase sensitivity but may cause false positives
- Video: MP4, AVI, MOV, and other OpenCV-supported formats
- Real time: Webcam input (change
VIDEO_PATHto0,1or the index of any external camera)
To detect kicks with different body parts:
# For ankle detection
CONTACT_LANDMARKS = [27, 28] # Left ankle, Right ankle
# For knee detection
CONTACT_LANDMARKS = [25, 26] # Left knee, Right knee
# For multiple points
CONTACT_LANDMARKS = [27, 28, 31, 32] # Ankles and Foot- Increase Sensitivity: Lower
CONTACT_THRESHOLDvalue - Decrease False Positives: Higher
CONTACT_THRESHOLDvalue - Faster Counting: Lower
COOLDOWN_FRAMESvalue - Prevent Double Counting: Higher
COOLDOWN_FRAMESvalue
No ball detected:
- Ensure ball is clearly visible in video
- Check lighting conditions
- Try adjusting video quality
False kick counts:
- Increase
CONTACT_THRESHOLDvalue - Increase
COOLDOWN_FRAMESfor longer pause between counts
Missed kicks:
- Decrease
CONTACT_THRESHOLDvalue - Ensure pose landmarks are properly detected
- Check if contact landmarks are appropriate for kicking style
Performance issues:
- Use smaller YOLO model (yolo11n.pt, yolo11s.pt)
- Reduce video resolution
- Process every nth frame only
This project is licensed under the MIT License - see the LICENSE file for details.