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.
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.
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.
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.
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.
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
- PyTorch
- YOLOv5
- CUDA
Vision
- OpenCV
- Calibration
- Annotation
Language
- Python