A collection of tools for GPU-accelerated video processing using OpenCV with CUDA support. This repository includes scripts for building OpenCV with CUDA support, environment setup, and example applications for video processing.
- GPU-accelerated video processing using OpenCV-CUDA
- Zero-copy frame processing with NVDEC
- Batched Sobel magnitude computation on GPU
- CUDA streams and events for optimized performance
- Optional Cupy kernels for median-border heuristic
- Two-stage pipeline: analyze first, encode later
- Ubuntu Linux
- NVIDIA GPU with CUDA support
- CUDA Toolkit
- Python 3.x
- CMake
- Git
- Clone this repository:
git clone htts://github.com/Orianexyz/opencv-cuda
cd opencv-cuda
- Run the installation script to install system dependencies:
./install.sh
- Build opencv-cuda with NVIDIA GPU support:
./build.sh
- Set up the environment:
source env_open_cuda.sh
- (Optional) Create a Conda virtual environment:
./conda_venv.sh
To verify CUDA support and basic functionality:
python test_cuda.py
This script demonstrates basic CUDA operations including:
- GPU matrix operations
- Box filtering
- Gaussian filtering
The cropper.py
script provides GPU-accelerated video cropping capabilities:
python cropper.py -i <input_directory> -o <output_directory> [options]
Options:
-i, --input
: Input directory containing MP4 files (default: "../videos")-o, --output
: Output directory for cropped videos (default: "../output/cropped_gpu")--fps
: Sample rate for analysis (default: 1)--cpu
: Force CPU processing even if CUDA is available
The env_open_cuda.sh
script sets up the following environment variables:
OpenCV_DIR
: Path to OpenCV CMake config filesPKG_CONFIG_PATH
: Path for pkg-configPYTHONPATH
: Python binding location
To build OpenCV with CUDA support:
./build.sh
This project relies on several key technologies:
- OpenCV - Computer vision library
- OpenCV Contrib - Additional OpenCV modules
- NVIDIA Video Codec SDK - Hardware-accelerated video encoding/decoding
- CUDA Toolkit - NVIDIA's parallel computing platform
- FFmpeg - Multimedia framework
- Cupy - GPU-accelerated NumPy implementation
This project is licensed under the MIT License - see the LICENSE.md file for details.
- OpenCV Documentation: https://docs.opencv.org/
- NVIDIA CUDA Documentation: https://docs.nvidia.com/cuda/
- NVIDIA Video Codec SDK Documentation: https://developer.nvidia.com/nvidia-video-codec-sdk/documentation
- FFmpeg Documentation: https://ffmpeg.org/documentation.html
- Cupy Documentation: https://docs.cupy.dev/
Contributions are welcome! Please feel free to submit a Pull Request.
- OpenCV team for the excellent computer vision library
- NVIDIA for CUDA and Video Codec SDK
- FFmpeg project for video processing capabilities