This project provides a Python script to monitor a CCTV RTSP stream using a YOLO object detection model accelerated with ONNX Runtime. It supports GPU acceleration on NVIDIA, Intel, and AMD hardware.
The CCTV stream is from V380 Pro IP camera, like this:
I also tested this using the DroidCam Webcam app.
Sample detection:
CPU and GPU Load:

- Real-time object detection on RTSP or webcam streams
- Uses Ultralytics YOLO models (
.pt), automatically exports to ONNX (.onnx) - Hardware acceleration via DirectML on Windows OS. Fallback to CPU.
- Displays detected objects with class names and confidence
- Shows real-time FPS and can skip frames to maintain target frame rate
- Draw custom monitoring line to raise alarm message whenever a detected object intersects it
- Python 3.8+
- Windows (DirectML/AMD GPU support), Linux (CUDA/NVIDIA GPU support), or Intel OpenVINO
- RTSP-compatible CCTV camera or webcam
Install dependencies with:
pip install -r requirements.txt
Contents of requirements.txt:
onnxruntime-directml
opencv-python
ultralytics
For NVIDIA GPU support, install
onnxruntime-gpuinstead ofonnxruntime-directml. For Intel GPU/CPU support, installonnxruntime-openvino.
-
Clone the repository:
git clone https://github.com/afdp777/cctv_monitor.git cd cctv_monitor -
Create and activate a virtual environment:
python -m venv venv venv\Scripts\activate # On Windows # or source venv/bin/activate # On Linux/macOS -
Install dependencies:
pip install -r requirements.txt -
Configure the stream URL:
- Edit
watch_cctv_gpu.pyand setstream_urlto your RTSP stream.
- Edit
-
Run the script:
python watch_cctv_gpu.py
The script tries to use the best available provider in this order:
CUDAExecutionProvider(NVIDIA GPU)OpenVINOExecutionProvider(Intel GPU/CPU)DmlExecutionProvider(AMD GPU via DirectML)- Falls back to CPU if no GPU provider is available
You can check which provider is active in the console output.
- The script will download and export the YOLO
.ptmodel to ONNX format on first run. - Class names are extracted from the Ultralytics model before export.
- For best performance, ensure your GPU drivers are up to date.
- The maximum value for the displayed
fpsis the actual frame rate of the video source. The displayedfpsgets lower depending on your GPU performance. Set thetarget_fpsat or below this lower frame rate.
MIT License