Loading repository data…
Loading repository data…
FlyingFathead / repository
Python+YOLOv8-based human/animal/object detection DVR framework with GUI, webUI and Telegram alerts
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
dvr-yolov8-detection is designed for real-time detection of humans, animals, or objects using the YOLOv8 model and OpenCV. Contrary to its name, we're now supporting models up to YOLOv11!
The program supports real-time video streams via RTMP or USB webcams, includes CUDA GPU acceleration for enhanced performance, and provides options for saving detections, triggering alerts and logging events.
The video preview can be run both in a GUI window and headless on a local web server using the included Flask web server setup.
Flask), 2-in-1
utils/)The project uses Python with YOLOv8 and OpenCV2 to perform object detection on either real-time video streams or batches of video files. It processes each video frame by frame, detecting humans by default (other YOLOv8-supported objects can be added as needed). The program can log detections into a separate log file, save detection frames with highlighted objects, and send out audio alerts via .
pyttsx3Configuration options are available in the config.ini file.
Note: Using CUDA-enabled OpenCV is recommended for faster operation. CUDA-enabled OpenCV2 needs to be compiled manually and installed separately, as the compiling process is highly dependent on your hardware setup. Refer to the "Troubleshooting" section for guidance and an example build script for OpenCV with CUDA.
Real-time detection also supports additional CUDA features such as CUDA video denoising (note: this feature requires CUDA and is often available only when OpenCV is compiled from source).
config.ini:🐳 For Docker setup, see the DOCKER_SETUP.md for a guide.
Clone the repository:
git clone https://github.com/FlyingFathead/dvr-yolov8-detection.git
cd dvr-yolov8-detection
1.2 (Install Miniconda or Anaconda if not already installed):
Download and install Miniconda (recommended):
For Linux/macOS:
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh
For Windows, download the installer from here and follow the installation instructions.
Set up the environment Conda/Mamba environment:
./setup_mamba_env.sh
This script creates a Conda/Mamba environment with the required dependencies.
Run the detection script:
./run_detection.sh
Clone the repository:
git clone https://github.com/FlyingFathead/dvr-yolov8-detection.git
cd dvr-yolov8-detection
Install the required Python packages:
pip install -r requirements.txt
This ensures that all dependencies are managed through the requirements.txt file.
Install OpenCV:
For a full version with GUI support (recommended):
pip install opencv-python
For CUDA-enabled OpenCV, you need to build it from source. Refer to the OpenCV documentation or check the build script for guidance.
Install FFmpeg:
On Ubuntu:
sudo apt-get install ffmpeg
On Windows and macOS, follow the instructions on the FFmpeg download page.
This project supports real-time object detection from RTMP streams or USB webcams using YOLOv8. The provided run_detection.sh script ensures the detection script runs continuously, automatically restarting if it exits.
(New in v0.155): The real-time detection now comes with a mini web server running on Flask that enables you to run the detection framework in your browser by default when headless and enable_webserver are set to true. This will make headless deployment very easy. Note that it listens on 0.0.0.0:5000 by default, which you might want to change (i.e. to 127.0.0.1:5000) for safety reasons.
Set up your RTMP server:
example-nginx.conf) to set up an RTMP loopback server.rtmp://127.0.0.1:1935/live.Run the detection script:
./run_detection.sh
Run the detection script with the --use_webcam option:
python3 yolov8_live_rtmp_stream_detection.py --use_webcam true
Specify webcam index (if needed):
python3 yolov8_live_rtmp_stream_detection.py --use_webcam true --webcam_index <number>
<number> with the index number of your webcam.utils/get_webcams.py tool to find available webcams and their index numbers.Alternatively, configure via config.ini:
use_webcam to true.webcam_index to your desired webcam index.Due to Docker being a popular install option, you can run the program headless and with a Flask based mini-web server included. Compared to the regular GUI verison, there is likely a small framerate dip and latency in the output, but other than that, the functionality is not too far off from the GUI variant.
In headless Docker installs, make sure that headless and enable_webserver are both set to true.
You can configure the program's parameters by editing the config.ini file. This allows you to set program parameters such as the input source, input stream address, output directory, confidence threshold, model variant, stream URL, and more.
An example NGINX configuration is provided in example-nginx.conf. This config sets up an RTMP server that listens on 127.0.0.1:1935 and allows local clients to publish and play streams.
To stream and process the video in real-time, use the ffmpeg_video_stream_loopback.sh script. Ensure your streaming client (e.g., OBS Studio) is set to stream to rtmp://127.0.0.1:1935/live.
Use the utils/loopback_test_unit_ffmpeg-python.py script to set up a loopback for your RTMP stream.
Install ffmpeg-python:
pip install -U ffmpeg-python
Run the loopback script:
python3 utils/loopback_test_unit_ffmpeg-python.py
Run the detection script:
python3 yolov8_live_rtmp_stream_detection.py
Configure your streaming client to stream to:
rtmp://127.0.0.1:1935/live
Note: Using NGINX as a loopback method is highly recommended for stability.
Mask detection areas: this is highly useful where detections need to be above certain threshold to be saved and registered with separate alerts. You can use the method to i.e. increase thresholds on the input image's detection areas to avoid false positives.
The masking can be done with a GUI rectangle painter util under ./utils/region_masker.py, i.e.:
python ./utils/region_masker.py
This will run a region masking utility that enables you to set special zones with a GUI interface (no headless mode yet!) and have it saved into a file (./data/ignore_zones.json by default; see config.ini on how to utilize the feature)
Use utils/batch_humdet_yolo8_opencv2.py to run YOLOv8 batch detection on directories of video files, suitable for faster offline use.
utils/test_stream_generator.py. When ran, the script generates synthetic video frames and streams them to your RTMP server using FFmpeg as a subprocess, enabling you to try out if your loopback works.test_stream_generator.py and keep it running in the background, then try to first use VLC to connect to your stream (VLC: Media -> Open Network Stream -> rtmp://127.0.0.1:1935/live/stream). If this works, the main detection script should work as well.config.ini.