Veerendra R. Patil
Project 03 — Vision
03 Computer vision·Perception

Real-Time Computer Vision & Distance Estimation

Detection is only half of perception. A bounding box tells you what and where in the frame — this system also answers how far, from a single camera.

RoleSole developer
StackPython · PyTorch · YOLOv5 · OpenCV · CUDA
InputSingle camera feed
OutputBoxes, confidence and real-world distance
Vision pipeline: camera frame, YOLOv5 detection, bounding box geometry, calibration, real-world distance overlay Camera Live video frame YOLOv5 Trained from scratch GPU inference · CUDA Bounding box Rim localisation Pixel geometry Calibration Pixel → metres Derived formula Distance Overlay + export Annotated video out
Perception pipeline — diagram drawn for this case study Fig. 01
01 — Overview

From pixels to metres

A detector that finds a basketball rim in a frame is useful. A system that also reports how far away that rim is, from one ordinary camera, is the difference between an object detector and a piece of perception a robot can act on.

This project trains the detector, derives the geometry, and puts both into a real-time video pipeline that draws its own answers back onto the frame.

02 — Model

Trained from scratch, not fine-tuned

  • Trained a custom YOLOv5 model from scratch on a labelled dataset built for this task, rather than adapting an off-the-shelf checkpoint.
  • Runs in real time on GPU, detecting basketball rims in a live feed.
03 — Distance

The geometry that makes one camera enough

A monocular camera cannot measure depth directly — but a target of known physical size gives it back. The apparent size of the rim in pixels falls off predictably with distance, so a calibrated pixel-to-real-world distance formula converts box geometry into a metric estimate.

Calibration is what makes it trustworthy: the relationship is fitted against known distances rather than assumed from lens specifications.

04 — Pipeline

Everything drawn back onto the frame

  • A real-time video pipeline overlaying bounding boxes, confidence scores and the computed distance on each frame.
  • Annotated video export, so a run can be reviewed, shared and checked against ground truth after the fact.
  • Built on OpenCV for capture, drawing and encoding, with CUDA keeping inference ahead of the frame rate.
05 — Demo

Running on a real court

Unedited output. The detector holds the rim through camera movement, occlusion from branches and a change of backdrop, and the distance estimate updates on every frame — 4.75 m in the opening shot.

Model output as rendered by the pipeline — box, confidence and distance drawn per frame Unedited capture
06 — Technologies

Model

  • PyTorch
  • YOLOv5
  • CUDA

Vision

  • OpenCV
  • Calibration
  • Annotation

Language

  • Python
07 — Repository

Source

Code on GitHub.

Veerendra R. Patil — © 2026 Back to index