WildTrack is an open-source pipeline for wildlife detection, segmentation, and tracking in videos. It combines your choice of wildlife detection models with SAM 2 into a unified incremental workflow that automatically finds, segments, and follows individual animals across frames β even with camera movement, occlusions, or multiple individuals.
Example: WildTrack automatically detects, segments, and tracks elephants across video frames, even with camera moves!
- Flexible Detection β choose from multiple models (MegaDetector, Community Fish Detector, or bring your own)
- Incremental Tracking β intelligently adds new animals only when they appear
- High-Quality Segmentation β SAM2-powered masks for precise individual tracking
- Hardware Optimized β supports CUDA, MPS, and CPU out of the box
- Simple CLI β process videos with a single command
Use WildTrack directly without downloading the source code:
pip install git+https://github.com/GerardCB/wildtrack.gitIf you plan to edit or contribute to the code:
# Clone repository
git clone https://github.com/GerardCB/wildtrack.git
cd wildtrack
# Install dependencies
pip install -e .wildtrack --video path/to/video_name.mp4 --visualize high-qualityOutputs will be saved in ./outputs/<video_name>/, including:
- masks_preview.mp4 β video of detected animals with painted masks (only if
--visualizeis notnone) - <video_name>_metadata.json β summary of detections, frames, merges
- <video_name>_masks.pkl β serialized SAM2 outputs and masks
WildTrack supports multiple detection models. Choose the best detector for your use case:
# List available detectors
wildtrack --list-detectors
# Use specific detector
wildtrack -v video.mp4 --detector megadetector-v5 --visualize fast| Detector | Best For | Notes |
|---|---|---|
megadetector-v5 |
Terrestrial wildlife, camera traps | Default detector |
community-fish |
Underwater footage, marine life | Requires ultralytics |
# Terrestrial wildlife (default)
wildtrack -v safari.mp4 --visualize fast
# Underwater/marine life
wildtrack -v reef.mp4 --detector community-fish --visualize fastWant to add your own detector? See our detector contribution guide!
| Category | Argument | Default | Description |
|---|---|---|---|
| Input/Output | -v, --video |
(required) | Path to input video file |
-o, --output-dir |
outputs |
Directory for output files | |
| Detection | --detector |
megadetector-v5 |
Detection model to use (run --list-detectors for options) |
-c, --confidence |
0.40 |
Minimum confidence threshold for detections | |
--detect-every |
10 |
Run detector every N frames (larger = faster) | |
--overlap-threshold |
0.3 |
IoU threshold to consider animal already tracked | |
| Processing | --device |
auto |
Compute device: cpu, mps, cuda, or auto |
--max-resolution |
720 |
Resize frames so max dimension = N pixels (smaller = faster) | |
--sample-every |
2 |
Process every Nth frame for segmentation (larger = faster) | |
--skip-postprocessing |
(flag) | Skip SAM2 post-processing step | |
| Visualization | --visualize |
none |
Output mode: none, fast (quick preview), or high-quality (overlay on original) |
| Track Merging | --skip-merge |
(flag) | Disable automatic merging of duplicate tracks |
--merge-iou |
0.4 |
IoU threshold for merging duplicate tracks | |
--merge-min-overlap |
3 |
Minimum overlapping frames to merge tracks |
# Basic usage with quick, low-resolution video preview
wildtrack -v elephants.mp4 --visualize fast
# Underwater fish detection
wildtrack -v reef_dive.mp4 --detector community-fish --visualize fast
# High-quality video output in custom directory
wildtrack -v elephants.mp4 -o results/ --visualize high-quality
# Fast processing for batch jobs (no visualization)
wildtrack -v video.mp4 --detect-every 20
# Sensitive detection for hard-to-spot animals
wildtrack -v nocturnal.mp4 --confidence 0.25
# Full control over processing
wildtrack -v test.mp4 \
--detector megadetector-v5 \
--confidence 0.35 \
--detect-every 20 \
--sample-every 3 \
--visualize high-quality \
--skip-mergeDetection vs Sampling:
--detect-every N: How often to look for new animals (affects detection only)--sample-every N: How often to process frames for tracking (affects segmentation quality)
Visualization Modes:
none: No video output (fastest, for batch processing)fast: Quick preview using processed frames (~2-5x faster)high-quality: Overlay masks on original video (best quality, slower)
Device Selection:
auto: Automatically picks CUDA β MPS β CPUcuda: Force NVIDIA GPU (fastest)mps: Force Apple Silicon GPUcpu: Force CPU (slowest, but works everywhere)
src/wildtrack/
βββ detectors/ # Detection models (MegaDetector, Community Fish, etc.)
βββ segmenters/ # SAM2 wrapper
βββ pipeline/ # incremental detection logic & orchestration
βββ utils/ # video, masks, visualization utilities
βββ cli.py # entrypoint for wildtrack command
βββ devices.py # device selection logic
This project is licensed under the MIT License.
See also the NOTICE file for details on third-party components used.
WildTrack builds on the incredible work by:
- Microsoft AI for Earth β MegaDetector
- Meta AI Research β Segment Anything 2
- WildHackers Community β Community Fish Detector