Grid-based fish detection and tracking from video. Divides each frame into a 7x4 grid (28 cells) and detects one fish per cell using background subtraction and HSV masking.
pip install -e .Place video files in data/input/videos/, then:
# Run the detection pipeline
python run.py
# Analyze per-fish tracking accuracy (after running the pipeline)
python analyze.py
# Analyze movement from the exported positions CSV (after running the pipeline)
python analyze_positions.py --run-dir data/output/<video_stem>This will create data/output/<video_stem>/analysis/ containing:
distance_summary.csv(per-fish distance traveled and coverage stats)fish01_xy_over_time.png…fish28_xy_over_time.png(x(t) and y(t) plots)
- Background model -- median of sampled frames across the video
- Background subtraction -- per-frame difference from the model, thresholded and morphologically cleaned
- HSV masking -- filters for bright objects (fish) in the subtracted frame
- Grid detection -- frame is divided into 28 cells (7 columns x 4 rows); the largest blob in each cell is taken as the fish
- Output -- annotated video, per-frame PNG snapshots, and a summary report
FishDetection/
├── run.py # Pipeline entry point
├── analyze.py # Per-fish tracking analysis
├── analyze_positions.py # Movement analysis from positions CSV
├── pyproject.toml # Package config and dependencies
├── analysis/ # CSV-based analysis helpers
├── data/
│ └── input/
│ └── videos/ # Place input videos here (gitignored)
└── src/
└── fishdetection/ # Core library
├── __init__.py
├── background_subtractor.py
├── base_masker.py
├── hsv_masker.py
├── base_pipeline.py
├── grid.py
└── pipeline.py