This repository provides a complete pipeline to generate synthetic underwater video and estimate object speed using optical flow techniques. It is designed for researchers and engineers working in underwater computer vision, robotics, or video analytics.
- Overview
- Features
- Scripts
- Installation
- Usage
- Parameters & Customization
- Results & Visualization
- Methodology
- Potential Applications
- License
- Contact
Underwater visual data is difficult to process due to challenges like poor lighting, turbidity, and distortion. This project helps:
- Generate synthetic underwater videos with moving objects.
- Track object movement using Lucas-Kanade optical flow.
- Estimate object speed in both pixels/frame and meters/second.
- Visualize speed statistics and motion path.
✅ Synthetic underwater video with smooth object motion
✅ Optical flow-based tracking (Lucas-Kanade method)
✅ CLAHE enhancement for underwater contrast
✅ Motion outlier filtering using MAD
✅ Gaussian smoothing for clean speed curves
✅ Real-time visualization and dual speed plots
✅ Speed output in px/frame and m/s
Generates a 10-second underwater-style video with a white object moving across a blue background.
- Script:
synthetic_video_generator.py
- Output:
synthetic_underwater_multi.mp4
- Purpose: Controlled video for speed estimation testing
Processes any underwater video to estimate object speed.
- Script:
speed_estimation.py
- Input: Underwater video file (real or synthetic)
- Output:
- Real-time tracking visualization (optional)
- Plots of speed (px/frame and m/s)
- Console report with statistics
Install Python 3.x and the following packages:
pip install opencv-python numpy matplotlib scipy
python synthetic_video_generator.py
Creates synthetic_underwater_multi.mp4
in your directory.
Update the path in speed_estimation.py
:
VIDEO_PATH = "synthetic_underwater_multi.mp4"
Then run:
python speed_estimation.py
- Press
q
to quit tracking early. - After processing, two side-by-side plots and a full speed report are shown.
Parameter | Description |
---|---|
VIDEO_PATH |
Input video path |
SHOW_TRACKING |
Show live tracking overlay |
SMOOTHING_SIGMA |
Gaussian smoothing strength |
PIXELS_PER_METER |
Conversion ratio (100 px = 1 m default) |
FPS |
Video frame rate |
SCALING_FACTOR |
Manual multiplier for speed |
feature_params |
Shi-Tomasi corner detection settings |
lk_params |
Lucas-Kanade flow tuning |
frame_count % 15 |
Refresh points every 15 frames |
🔴 Tracking Overlay: Red dots show features, green lines show motion vectors.
📈 Plots (side-by-side):
-
Speed in px/frame:
- Light blue: Raw speeds
- Blue: Smoothed curve
- Red dashed line: Mean with shaded ±1 std dev
-
Speed in m/s:
- Green: Converted speed
- Red dashed line: Median with ±1 std dev shaded
📊 Console Output:
=== FINAL REPORT ===
Mean speed: 0.50 px/frame
Median speed: 0.44 px/frame
Std deviation: ±0.24 px/frame
=== REAL-WORLD ESTIMATE ===
Mean speed: 0.15 m/s
Median speed: 0.13 m/s
Variation (std): ±0.07 m/s
-
CLAHE Preprocessing: Improves contrast in murky underwater frames.
-
Feature Detection (Shi-Tomasi): Identifies good points to track.
-
Optical Flow Tracking (Lucas-Kanade): Tracks feature movement between frames.
-
Camera Motion Compensation: Estimates background shift using affine transformation.
-
Speed Calculation: Measures point displacements minus camera motion → filters outliers using MAD → applies Gaussian smoothing.
-
Conversion to Real Units: Speed (px/frame) → meters/second using FPS and pixels-per-meter ratio.
- Benchmarking underwater tracking algorithms
- Marine life motion analysis
- AUV/ROV path tracking
- Underwater robotics simulation
- Educational demos in vision and robotics
© 2025 [Srinath V V] All rights reserved. Private and proprietary — reproduction or distribution without permission is strictly prohibited.
📫 Feel free to raise issues or connect via GitHub: github.com/srinathvv-dev
🎥 Happy Tracking & Speed Estimation! 🌊🐠