A Python application that uses computer vision to perform real-time motion tracking with different modes: hand tracking, face mesh detection, pose estimation, and holistic tracking.
-
Multiple Tracking Modes:
- Hand Tracking - Detect and track hand landmarks and gestures
- Face Mesh - Detailed facial landmark tracking with 468 points
- Pose Estimation - Full body posture tracking
- Holistic Tracking - Combined tracking of face, pose, and hands
-
User-Friendly Interface:
- Modern, clean UI built with Tkinter
- Intuitive card-based menu system
- Real-time FPS counter
- Loading animations between screens
-
Robust Error Handling:
- Graceful recovery from camera errors
- Dependency verification on startup
- Comprehensive error messaging
Main menu with tracking mode selection cards
Hand tracking mode with landmark visualization
Face mesh tracking with detailed facial landmarks
Full body pose estimation tracking
Combined tracking of face, pose, and hands
- Python 3.7+
- OpenCV (
cv2) - MediaPipe
- NumPy
- PIL (Pillow)
- Tkinter (usually comes with Python)
-
Clone this repository:
git clone https://github.com/yourusername/motion-tracking-suite.git cd motion-tracking-suite -
Install the required dependencies:
pip install opencv-python mediapipe numpy pillow -
Run the application:
python tracking_app.py
The core class that manages the entire application. It:
- Initializes the UI and MediaPipe models
- Creates the main menu interface
- Handles starting and stopping tracking
- Processes video frames with the selected tracking mode
- Manages error handling and resource cleanup
Defines the visual styling for the application:
- Color scheme constants
- Style configurations for buttons, frames, and labels
- Sets up a consistent visual language throughout the app
Manages the animated loading indicator:
- Creates an animated circular loading indicator
- Controls animation states (start/stop)
- Renders frames with varying opacity for a smooth effect
The heart of the tracking functionality. For each video frame:
- Converts the frame to RGB (required by MediaPipe)
- Processes the frame with the selected MediaPipe model
- Draws landmarks and connections on the frame
- Adds information overlay with FPS counter and mode indicator
- Handles exceptions with error counting and recovery
Initializes the tracking mode:
- Sets up the UI for video display
- Opens the webcam
- Creates the video canvas
- Starts the frame update loop
Continuous frame processing loop:
- Captures frames from the webcam
- Processes frames with the selected tracking mode
- Resizes and displays the processed frames
- Schedules the next frame update
- Handles errors with appropriate recovery
-
Initialization:
- MediaPipe models for hand, face, pose, and holistic tracking are initialized
- The modern UI theme is applied
- The main menu is created with selectable tracking modes
-
Tracking Mode Selection:
- User selects a tracking mode from the main menu
- A loading animation is displayed during initialization
- The selected model is activated, and webcam capture begins
-
Real-time Processing:
- Video frames are continuously captured from the webcam
- Each frame is processed by the selected MediaPipe model
- Visual landmarks are drawn on the frames
- Processed frames are displayed in real-time
- FPS and mode information are overlaid on the video
-
Error Handling:
- The application monitors for errors during frame processing
- If too many consecutive errors occur, tracking is stopped
- Resources are properly released when the application closes
The application uses several MediaPipe models:
- Hands - Detects 21 landmarks on each hand
- Face Mesh - Tracks 468 facial landmarks
- Pose - Tracks 33 body landmarks
- Holistic - Combines face, pose, and hand tracking into one model