-
CUDA installation : https://docs.nvidia.com/cuda/archive/10.0/cuda-installation-guide-linux/index.html
-
Download
- CMake : https://cmake.org/download/
- Note ! : a pair of opencv and opencv_contrib version should be matched
- OpenCV : https://github.com/opencv/opencv/releases
- OpenCV Contrib : https://github.com/opencv/opencv_contrib/releases
- CUDA (login needed) : https://developer.nvidia.com/cuda-toolkit-archive
- CUDNN (login needed) : https://developer.nvidia.com/rdp/cudnn-archive
- TBB : https://github.com/intel/tbb/releases
- EIGEN : https://eigen.tuxfamily.org/index.php?title=Main_Page
-
Intall required packages (Only Ubuntu)
$ sudo apt-get install -y \
ffmpeg \
libgtk2.0-dev libgtk-3-dev \
libavcodec-dev libavformat-dev libavutil-dev libavdevice-dev libavresample-dev libswscale-dev \
gfortran libblas-dev liblapack-dev \
python3-dev python3-numpy python3-py python3-pytest \
qt5-default \
zlib1g-dev \
libgl1 \
libglvnd-dev \
pkg-config
- Set CMake options
WITH_CUDA : ON
WITH_TBB : ON
WITH_FFMPEG : ON
WITE_EIGEN : ON
OPENCV_EXTRA_MODULES_PATH : <your_opencv_contrib_path>/modules
OPENCV_ENABLE_NONFREE : ON
OPENCV_GENERATE_PKGCONFIG : ON
EIGEN_INCLUDE_PATH : <your_eigen_path>
ENABLE_FAST_MATH : ON
BUILD_opencv_world : ON
BUILD_TEST : OFF
BUILD_PERF_TEST : OFF
BUILD_PACKAGE : OFF
BUILD_opencv_cudacodec : ON (NVIDIA VIDEO CODEC SDK is requried)
WITH_1394 : OFF
- CUDA options
- Check CUDA_ARCH_BIN in CMAKE here : https://developer.nvidia.com/cuda-gpus
CUDA_ARCH_BIN : 6.1 (for GTX 1050 laptop / GTX 1080 Ti / MX150)
- TBB options
TBB_DIR : <your_tbb_folder>/tbb/cmake
TBB_ENV_INCLUDE : <your_tbb_folder>/tbb/include/tbb
TBB_ENV_LIB : <your_tbb_folder>/tbb/lib/intel64/vc14/tbb.lib
TBB_ENV_LIB_DEBUG : <your_tbb_folder>/tbb/lib/intel64/vc14/tbb_debug.lib
- (Options) Save cuda_runtime.h file as "UNICODE - CODE PAGE 1200" to remove "warning C4819" in VS2017
- Reference : https://lucetewoo.tistory.com/15
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\include\cuda_runtime.h
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\include\cuda_runtime_api.h
c:\program files\nvidia gpu computing toolkit\cuda\v10.2\include\sm_20_intrinsics.h
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\include\cuda.h
OpenCV 4.x version basically does not support udacodec::VideoReader function. Additional steps are required to use cudacodec [1].
-
Download NVIDIA VIDEO CODEC SDK : https://developer.nvidia.com/nvidia-video-codec-sdk
-
After extracing zip file, copy all header files in <video_codec_sdk>/interface into both 1) /usr/local/cuda/include and 2) /usr/local/cuda-10.0/include
-
Check the system architecture
$ uname -a
Linux username 5.3.0-62-generic #56~18.04.1-Ubuntu SMP Wed Jun 24 16:17:03 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
-
Copy all library files in <video_codec_sdk>/Lib/linux/stubs/(architecture) into both 1) /usr/local/cuda/lib64 and 2) /usr/local/cuda-10.0/lib64
-
In CMake, set WITH_NVCUVID = ON
-
Build OpenCV
-
Run source code : https://github.com/opencv/opencv/blob/master/samples/gpu/video_reader.cpp
Results:
CPU : Avg : 2.76995 ms FPS : 361.017 Frames 987
GPU : Avg : 0.312265 ms FPS : 3202.41 Frames 995
Refereces [1] https://jamesbowley.co.uk/accelerate-opencv-4-2-0-build-with-cuda-and-python-bindings/
https://answers.opencv.org/question/95148/cudalegacy-not-compile-nppigraphcut-missing/