The Problem

Live CCTV feeds are often high‑resolution, which makes per‑frame inference with deep‑learning detectors costly. Operators need a way to run object detection at frame‑rates that keep up with the video while still visualising results on the original high‑resolution imagery.

What This Does

CCTV_YOLO ships a minimal Python service that:

  1. Loads the pre‑trained YOLOv5n6 checkpoint (yolov5n6.pt).
  2. Pulls a live video stream (the Las Vegas sidewalk cam used in the demo).
  3. Down‑samples each incoming frame to 320 × 180 for inference, then maps the resulting bounding boxes back onto the original high‑resolution frame.
  4. Exposes the processed stream through a Gradio web UI (app.py).

The repository consists of four top‑level items:

FileRole
README.mdUser‑facing overview, usage instructions, and demo link.
app.pyEntrypoint; builds the model, defines the detection callback, and launches the Gradio interface.
requirements.txtPip‑based dependency list (torch, torchvision, opencv‑python, gradio, etc.).
yolov5n6.ptSerialized YOLOv5n6 weights used for inference.

No additional modules, configuration files, or data‑persisting layers are present.

How It Is Wired

Execution starts with python app.py (the only documented entry point). The script performs the following linear flow:

  1. Model loadingtorch.hub.load (or torch.load) reads yolov5n6.pt into a torch.nn.Module. This is the sole heavyweight object and lives for the process lifetime.
  2. Gradio UI constructiongradio.Interface (or gradio.Blocks) registers a Python callback (e.g., process_frame) that receives a raw video frame. The UI runs a lightweight HTTP server on a local port.
  3. Frame acquisition – Inside the callback the code opens the remote CCTV URL with OpenCV (cv2.VideoCapture). Each frame is read, resized to 320 × 180, and converted to a tensor for the model.
  4. Inference – The model runs model(frame_tensor) producing detection tensors (boxes, scores, class IDs). Post‑processing applies the hard‑coded thresholds (conf 0.25, iou 0.45, max 100).
  5. Result mapping – Detected box coordinates are scaled back to the original resolution, and cv2.rectangle / cv2.putText draw the annotations.
  6. Return – The annotated high‑resolution frame is handed back to Gradio, which streams it to the browser.

External effects are limited to:

  • Network I/O – pulling the live CCTV stream.
  • GPU/CPU usage – inference on the loaded model (CUDA if available).

No files are written, no databases accessed, and no other services are contacted. Consequently, the blast radius of a change is confined to app.py; any modification to model loading, inference thresholds, or the frame‑scaling logic will directly affect the UI output.

How To Use It

# Clone the exact repo referenced in the brief
git clone https://github.com/moses-y/CCTV_YOLO.git
cd CCTV_YOLO

# Install the declared Python dependencies
pip install -r requirements.txt

# Start the Gradio service
python app.py

The README states these commands verbatim; no hidden environment variables or config files are required. After the script starts, open the printed URL (typically http://127.0.0.1:7860) in a browser to view the live annotated stream.

Real‑World Use

A city‑traffic monitoring center could embed this service behind an internal reverse proxy, replace the hard‑coded CCTV URL with its own camera feed, and optionally swap yolov5n6.pt for a domain‑specific model (e.g., vehicle‑type classification). The low‑resolution inference keeps latency below ~30 ms per frame on a modest GPU, while operators still see detections over the full‑resolution video.

Code Health & Issues

  • Medium – No test suite – repository contains no tests/ directory or test files.
  • Medium – No CI/CD – no .github/workflows/ or other pipeline definitions.
  • Medium – No LICENSE file – repository lacks an explicit license despite the README claiming MIT; legal status is ambiguous.
  • Low – No lockfile – dependencies are listed only in requirements.txt, making reproducible builds non‑deterministic.

No additional static analysis warnings were found.

The Bottom Line

CCTV_YOLO delivers a clear, single‑file demo of low‑resolution YOLO inference with high‑resolution visualisation, suitable for quick prototyping or as a reference implementation. Its simplicity is a strength, but the lack of tests, CI, and a proper license limits production readiness. Engineers needing a lightweight, adaptable pipeline for real‑time CCTV analytics can adopt it, provided they add their own testing, CI, and licensing compliance.