Skip to content

Orianexyz/opencv-cuda

Repository files navigation

OpenCV-CUDA Video Processing Tools

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.

Features

  • 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

Prerequisites

  • Ubuntu Linux
  • NVIDIA GPU with CUDA support
  • CUDA Toolkit
  • Python 3.x
  • CMake
  • Git

Installation

  1. Clone this repository:
git clone htts://github.com/Orianexyz/opencv-cuda
cd opencv-cuda
  1. Run the installation script to install system dependencies:
./install.sh
  1. Build opencv-cuda with NVIDIA GPU support:
./build.sh
  1. Set up the environment:
source env_open_cuda.sh
  1. (Optional) Create a Conda virtual environment:
./conda_venv.sh

Usage

Testing CUDA Support

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

Video Cropping Tool

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

Environment Variables

The env_open_cuda.sh script sets up the following environment variables:

  • OpenCV_DIR: Path to OpenCV CMake config files
  • PKG_CONFIG_PATH: Path for pkg-config
  • PYTHONPATH: Python binding location

Building from Source

To build OpenCV with CUDA support:

./build.sh

Dependencies

This project relies on several key technologies:

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

References

  1. OpenCV Documentation: https://docs.opencv.org/
  2. NVIDIA CUDA Documentation: https://docs.nvidia.com/cuda/
  3. NVIDIA Video Codec SDK Documentation: https://developer.nvidia.com/nvidia-video-codec-sdk/documentation
  4. FFmpeg Documentation: https://ffmpeg.org/documentation.html
  5. Cupy Documentation: https://docs.cupy.dev/

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Acknowledgments

  • OpenCV team for the excellent computer vision library
  • NVIDIA for CUDA and Video Codec SDK
  • FFmpeg project for video processing capabilities

About

OpenCV fork with custom CUDA support on top

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published