Minimal, notebook-first workflow for measuring the speed of moving objects from a recorded video or a live webcam stream — all inside Google Colab.
- Run entirely in Google Colab (no local setup)
- Custom Graph for Pixel Coordinate Calculation
- Works with uploaded video files or live webcam (Colab JS capture)
- Calibrated real-world speed estimation (px → meters)
- Frame-by-frame object tracking with smoothing
- Overlay: trajectory, instantaneous + average speed
- Modular cells you can remix
- Custom Color Assignment
| Section | Purpose |
|---|---|
| Setup & Imports | Install + import libraries |
| Config | Tunable params (FPS override, smoothing, detection model) |
| Media Input | Upload video / activate webcam |
| Calibration | Convert pixels → meters |
| Detection | Locate object(s) per frame |
| Tracking | Persist identity + position history |
| Speed Computation | Distance / time with smoothing |
| Visualization | Overlay bounding boxes, path, speed text |
| Export | Save processed MP4 + metrics CSV |
- Read frame (video or webcam)
- Detect object (centroid or bounding box)
- Track motion: store sequential positions
- Compute frame delta distance in pixels
- Convert to meters using:
meters = pixels * (meters_per_pixel) - Speed (m/s) = delta_meters / delta_time
Then optionally: km/h = m/s * 3.6 - Apply smoothing (moving average or exponential)
- Draw overlays + write out frame
| Parameter | Description | Example |
|---|---|---|
PIXEL_BASELINE |
Pixel length of known distance | 420 |
REAL_DISTANCE_M |
Real distance in meters | 5.0 |
SMOOTH_WINDOW |
Moving average window (frames) | 5 |
MIN_CONF |
Detection confidence threshold | 0.4 |
OUTPUT_FPS |
Override if metadata wrong | 30 |
Meters-per-pixel = REAL_DISTANCE_M / PIXEL_BASELINE
- Simple: Color threshold / contour (fast, controlled scenes)
- Intermediate: Background subtraction (static camera)
- Robust: Pretrained model (e.g. YOLO) for general objects
Swap the detection cell to upgrade accuracy without rewriting the rest.
- Use high-FPS source (≥30fps)
- Avoid motion blur (good lighting)
- Keep camera stable (mounted)
- Calibrate using longest measurable distance
- Prefer perpendicular camera angle to motion plane
- Multi-object tracking
- Perspective (homography) correction
- Auto baseline detection (lane markers etc.)
- Confidence bands on speed
- Edge device adaptation
- Roboflow community for video + geometry tools
- Colab for frictionless experimentation
- YOLO / Ultralytics / Supervision / OpenCV
Questions? Open an Issue with:
- Example frame
- Video FPS
- Calibration details
- Detection method used
Built for clarity, remixability, and learning. Enjoy measuring motion.