Real-time FPV data collection, labeling, training, inference, and depth-estimation pipeline for Crazyflie tracking.
The repository is focused on:
- collecting raw FPV data from a USB video receiver,
- exporting videos and sampled images,
- semi-automatic annotation with OpenCV trackers,
- organizing labels by class in a structure that supports later train/val/test splitting,
- training/testing/comparing YOLO models,
- running live YOLO inference on receiver feed,
- running flight control and YOLO live view concurrently via one integrated runtime,
- estimating depth with UniDepth v2 (and an additional bbox-width baseline).
Build an end-to-end workflow for Crazyflie CV experiments: capture data, label it, prepare YOLO datasets, train/evaluate models, run live inference, and estimate depth.
Crazyflie-FPV-Tracking/
├── data/
│ ├── constants.py # Data/label/dataset/backup config
│ ├── images_get_data.py # Capture periodic still frames
│ ├── videos_get_data.py # Record continuous video with FPS matching
│ ├── track_label_video.py # Semi-auto tracker-based labeling
│ ├── view_labeling.py # Review/delete labeled frames
│ ├── create_dataset.py # Merge label sessions into one dataset
│ ├── prepare_yolo_dataset.py # Build YOLO train/val/test split
│ ├── upload_data_drive.py # Zip+upload raw/labels backup to Drive
│ └── utils.py # Shared camera/tracker/session helpers
├── models/
│ ├── constants.py # YOLO train/test/compare config
│ ├── train_yolo.py # Train YOLO model
│ ├── test_yolo.py # Evaluate selected YOLO weights
│ ├── compare_models.py # Compare multiple model refs on one split
│ └── utils.py
├── inference/
│ ├── constants.py # Live inference config
│ ├── live_inference.py # Realtime YOLO inference on camera
│ └── utils.py
├── flight_vision/
│ ├── main.py # Combined drone_control + YOLO entrypoint
│ ├── app.py # Concurrent app orchestration
│ ├── camera_sources.py # Frame-source interfaces and receiver factory
│ ├── vision_runtime.py # YOLO + overlay + OpenCV presenter runtime
│ ├── constants.py # Integrated runtime defaults
│ └── README.md
├── depth_estimation/
│ ├── unidepth/
│ │ ├── constants.py # UniDepth image/video config
│ │ ├── depth_image_inference.py
│ │ ├── depth_video_inference.py
│ │ ├── unidepth_v2.py
│ │ └── utils.py
│ └── direct_depth_estimation/
│ ├── constants.py # Bbox-width distance baseline config
│ ├── bbox_dist_estimator.py
│ └── utils.py
├── scripts/
│ ├── *.sh # One launcher per feature
│ └── README.md # Launcher catalog
├── setting_up_camera/
│ ├── README.md # Receiver setup and debugging notes
│ └── get_visual.py # Minimal live camera test
├── tests/
│ └── test_*.py # Integration/system tests
├── runs/ # Training/eval/comparison outputs
├── pyproject.toml
├── uv.lock
└── README.md
Generated data (not committed) is created under:
data/raw_data/data/labels/data/depth/runs/
- Linux machine (tested with
/dev/videoX+ V4L2 flow) - USB FPV receiver exposed as a video device
- Python 3.13
uvpackage/environment manager- GPU is recommended for UniDepth/YOLO inference and training
curl -LsSf https://astral.sh/uv/install.sh | shRun from repository root:
uv python install 3.13
uv venv --python 3.13
source .venv/bin/activate
uv syncAlternative (no manual activation):
uv run python --versionTracker APIs like CSRT/KCF/MOSSE require contrib modules. This project depends on:
opencv-contrib-python
Quick check:
uv run python -c "import cv2; print(cv2.__version__, hasattr(cv2,'TrackerCSRT_create'))"Expected final value is True.
./scripts/capture_images.shOutput:
data/raw_data/images_session_<timestamp>/images/*.jpgdata/raw_data/images_session_<timestamp>/meta.csv
./scripts/capture_video.shOutput:
data/raw_data/<DRONE_TYPE>_session_<timestamp>/video.avi
Important:
- video writer FPS is matched to measured capture FPS to avoid sped-up playback.
At minimum update:
VIDEO_PATHLABEL_CLASS_NAMECLASS_ID
./scripts/label_video.shIf class-matched weights are present under yolo_best_models/, labeling can use YOLO as primary bbox source and CSRT as fallback. Configure with:
LABEL_YOLO_BEST_MODELS_DIRLABEL_YOLO_ENABLED_AT_STARTLABEL_YOLO_CONF_THRESHOLDLABEL_YOLO_MAX_CENTER_JUMP_RATIO
q: quitp: pause/resumer: redraw ROI and reinitialize trackery: toggle YOLO assist on/off (when compatible weights are loaded)
Each run is saved to a unique session directory:
data/labels/<class_name>/all_data/label_session_<timestamp>/
├── images/
├── labels/
└── meta.csv
This prevents overwrite across repeated labeling sessions of the same class.
Optional label review:
./scripts/review_labels.sh --session data/labels/<class_name>/all_data/<label_session_timestamp>- Use
LABEL_CLASS_NAMEfor folder organization. - Use
CLASS_IDfor YOLO numeric labels. - If two visual variants are the same detection class, keep the same
CLASS_ID. - If they are different detection classes, use different
CLASS_IDvalues consistently across the dataset.
./scripts/create_dataset.sh --class-name <class_name> --overwriteBy default this collects all direct subfolders under:
data/labels/<class_name>/<LABEL_ALL_DATA_DIR>/
and includes folders that contain both images/ and labels/ (folder name can be anything, not only label_session_*).
Default output:
data/labels/<class_name>/<class_name>_dataset/
├── images/
├── labels/
└── manifest.csv
Set YOLO split options in data/constants.py (YOLO_* keys), then run:
./scripts/prepare_yolo_dataset.shOutput:
data/labels/<class_name>/<class_name>_yolo/
├── images/train|val|test
├── labels/train|val|test
├── split_manifest.csv
└── dataset.yaml
Edit models/constants.py for:
- dataset reference (
YOLO_TARGET_CLASS_NAME,YOLO_OUTPUT_DATASET_NAME) - training/eval settings
- model refs for comparison
./scripts/train_yolo.sh./scripts/test_yolo.sh./scripts/compare_models.shOutputs are written under:
runs/models/runs/evaluation/runs/comparison/
Set DEPTH_IMAGE_* in depth_estimation/unidepth/constants.py, then run:
./scripts/depth_image.shOutput:
- depth array (
.npy) - depth visualization (
.png)
Set DEPTH_VIDEO_* in depth_estimation/unidepth/constants.py, then run:
./scripts/depth_video.shConfigure depth_estimation/direct_depth_estimation/constants.py, then run:
uv run python depth_estimation/direct_depth_estimation/bbox_dist_estimator.pyLive mode:
uv run python depth_estimation/direct_depth_estimation/bbox_dist_estimator.py --liveSet inference/constants.py (camera + weights), then run:
./scripts/live_inference.shControls:
qorESCto quit
Feature launchers are in scripts/ (data capture, labeling, dataset prep, training, testing, depth, live inference, backups).
Full launcher catalog:
scripts/README.md
Run repository integration/system tests:
./scripts/run_tests.sh- Verify device path with:
v4l2-ctl --list-devices- See
setting_up_camera/README.mdfor full receiver checks.
- Generated data under
data/raw_data,data/labels, anddata/depthis ignored bydata/.gitignore. scripts/*.shcan be run from repo root or via absolute path.