A Python application for capturing synchronized video from two USB cameras with integrated biomechanical analysis for golf swing evaluation. Features a GUI for camera configuration, recording control, and automated analysis.
- Dual Camera Capture: Simultaneously capture from 2 USB cameras with synchronized recording
- GUI Interface: Tabbed interface for camera setup, recording control, and analysis visualization
- Golf Swing Analysis: Integrated MediaPipe pose detection and biomechanical analysis
- Lateral sway tracking (face-on view)
- Shoulder turn, hip turn, and X-factor measurement (down-the-line view)
- Frame-by-frame navigation through analysis results
- Maximum metrics tracking and display
- Multiple Recording Sessions: Support for sequential recording sessions (configure → record → analyze → record again)
- Platform Support: Windows and Linux with platform-appropriate camera backends and defaults
- Low CPU Usage:
- Threaded capture to prevent blocking
- Efficient video codecs (H.264, XVID)
- Minimal buffering to reduce memory overhead
-
Install Python 3.7 or higher
-
Install dependencies:
pip install -r requirements.txtRun the GUI application:
python scripts/camera_setup_recorder_gui.pyOn Windows (cameras auto-detected from config_windows.json):
python scripts/camera_setup_recorder_gui.py
# Or with explicit camera IDs:
python scripts/camera_setup_recorder_gui.py --camera1 0 --camera2 1On Linux (default cameras 0 and 1):
python scripts/camera_setup_recorder_gui.py --camera1 0 --camera2 1The application provides a tabbed interface with 4 tabs:
- Camera 1 Setup: Configure camera properties (brightness, contrast, exposure, etc.)
- Camera 2 Setup: Configure camera properties for the second camera
- Recording: Start/stop recording with live preview
- Analysis: View analysis results with frame navigation
The typical workflow supports multiple recording sessions:
-
Configure Cameras (Tabs 1 & 2):
- Adjust camera properties using W/X to select, +/- to adjust
- Save settings with 'S' key
- Reset to defaults with 'R' key
-
Record (Tab 3):
- Press Space to start/stop recording
- Recordings are automatically saved to the
recordings/directory
-
Analyze (Tab 4 - Automatic):
- Analysis starts automatically after recording completes
- View biomechanical metrics and pose detection results
- Navigate frames with A/Left Arrow (previous) and D/Right Arrow (next)
-
Record Again:
- Return to Tab 3 and press Space to start a new recording session
- Camera resources are automatically managed between sessions
- Tab/1/2/3/4: Switch between tabs
- Q/ESC: Quit application
- W/X: Select property (previous/next)
- +/-: Adjust current property (increase/decrease)
- S: Save camera settings
- R: Reset camera settings to defaults
- Space: Start/Stop recording
- A/Left Arrow: Navigate to previous frame
- D/Right Arrow: Navigate to next frame
python scripts/camera_setup_recorder_gui.py [OPTIONS]
Options:
--camera1 ID Camera 1 ID (default: 0 on Linux, from config_windows.json on Windows)
--camera2 ID Camera 2 ID (default: 1 on Linux, from config_windows.json on Windows)
--width WIDTH Resolution width (default: 1280)
--height HEIGHT Resolution height (default: 720)
--fps FPS Frame rate (default: 60)Recorded videos are saved in the recordings/ directory with filenames:
recording_YYYYMMDD_HHMMSS_camera1.mp4recording_YYYYMMDD_HHMMSS_camera2.mp4
Analysis results include:
- Camera 1 (face-on): Lateral sway metrics (left/right displacement)
- Camera 2 (down-the-line): Rotation metrics (shoulder turn, hip turn, X-factor)
- Detection rates for each camera
- Maximum values for all metrics
- Frame-by-frame values for navigation
- Resolution: 720p (1280x720) provides a good balance between quality and performance
- Frame Rate: 60 FPS is recommended; reduce to 30 FPS if CPU usage is high
- Hardware Acceleration: The app automatically tries to use hardware-accelerated codecs when available
- Close Other Applications: Free up CPU resources for camera capture and analysis
- Uses DirectShow backend (
cv2.CAP_DSHOW) for better camera compatibility - Camera configuration is stored in
config_windows.json(auto-detected) - To regenerate camera configuration:
python scripts/detect_windows_cameras.py - Default cameras: Loaded from
config_windows.jsonif available, otherwise 0 and 2
- Uses V4L2 backend (default)
- Default cameras: 0 and 1
- Cameras cannot be opened simultaneously by multiple processes (GUI automatically manages this)
See docs/PLATFORM_CONFIG.md for detailed platform configuration information.
- Windows: Run
python scripts/detect_windows_cameras.pyto automatically detect and configure cameras - Check camera IDs: Try 0, 1, 2, etc.
- Ensure cameras are not being used by other applications (OBS, Zoom, etc.)
- On Windows, check Device Manager for camera availability
- Run
python tests/test_cameras.pyto find available cameras - Check
config_windows.jsonfor Windows camera configuration
- Reduce resolution (try 640x480)
- Reduce FPS (try 30)
- Close other applications
- Check if hardware acceleration is working (see codec selection in console output)
- Check if
recordings/directory exists and is writable - Verify cameras are providing frames (check console output)
- Ensure cameras are not locked by another process (especially on Linux)
- Ensure MediaPipe is installed correctly:
pip install "mediapipe>=0.10.0,<0.10.30" - Analysis runs even if no poses are detected (detection rate will be 0%)
- Check that video files are fully written before analysis starts (automatic delay included)
- The application automatically manages camera resources between sessions
- If issues persist, ensure no other applications are using the cameras
- Check console output for camera lock warnings
The project includes comprehensive test suites:
python -m pytest tests/test_gui.py -vpython -m pytest tests/test_analysis_navigation.py -v
python -m pytest tests/test_analysis_workflow.py -vpython -m pytest tests/test_config_to_record_workflow.py -vpython tests/test_cameras.pySee test README files for detailed information:
- Synchronization: Timestamp-based frame matching with configurable tolerance
- Threading: Each camera runs in its own thread to prevent blocking
- Buffering: Minimal buffering (buffer size 2) to reduce latency and memory usage
- Codecs: Automatically selects best available codec (H.264 > XVID > mp4v)
- Analysis: MediaPipe Pose Detection (model complexity 2) with custom biomechanical calculations
- Resource Management: Automatic camera release/reacquisition for multiple recording sessions
See PROJECT_STRUCTURE.md for detailed project organization.
Free to use and modify for your projects.