Path: blob/master/Getting-Started-OpenCV-CUDA-Module/README.md
3119 views
OpenCV GPU Support
This repository contains the code for Getting Started with OpenCV CUDA Module
Getting Started
Our code is tested using Python 3.7.5, but it should also work with any other python3.x. If you'd like to check your version run:
Virtual Environment
Let's create a new virtual environment. You'll need to install virtualenv package if you don't have it:
Now we can create a new virtualenv variable and call it env
:
The last thing we have to do is to activate it:
Numpy
Install numpy package by running:
Installing CUDA
The code was tested using CUDA Toolkit 10.2. Please follow the official instruction to download CUDA Toolkit 10.2 or higher.
OpenCV with CUDA Support
In this blog post, we're using OpenCV with CUDA support to accelerate OpenCV algorithms. That is why we will need to customize the OpenCV library build and make it from scratch. To do so:
Install dependencies:
Download the latest OpenCV version from the official repository:
Unzip the downloaded archives:
Rename the directories to match CMake paths:
Compile OpenCV:
Create and enter a build directory:
Run CMake to configure the OpenCV build. Don't forget to set the right pass to the PYTHON_EXECUTABLE
. If you are using the CUDA version different from 10.2
, please change the last 3 arguments accordingly.
Check the output and make sure that everything is set correctly. After that we're ready to build it with:
Make sure, you didn't get any errors. Then run the following command:
which creates the necessary links and cache to our freshly built shared library.
Rename the created Python3 bindings for OpenCV to cv2.so
:
The last step is to create a symlink of our OpenCV cv2.so
into the virtual environment installed packages:
Running the Demo
C++
You first need to compile .cpp file with the following command:
After that to run the demo, you will need to pass:
path to the video file,
device, to choose between CPU and GPU inference. By default, the device is set to "cpu".
For example:
Python
To run the demo, you will need to pass:
--video
argument to set the path to the video file,--device
to choose between CPU and GPU inference. By default, the device is set to "cpu".
For example:
AI Courses by OpenCV
Want to become an expert in AI? AI Courses by OpenCV is a great place to start.