Rebuild my OpenCV4.3 for the use of Python3 CUDA

Command for building OpenCV from source:

$ cd opencv4.3

$ cd build

$ cmake -DCMAKE_C_COMPILER=$(which gcc-8) \
-D CMAKE_CXX_COMPILER=$(which g++-8)
\
-D CMAKE_BUILD_TYPE=RELEASE \
-D INSTALL_C_EXAMPLES=ON \ 
-D INSTALL_PYTHON_EXAMPLES=ON \ 
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_build_4.3/opencv_contrib/modules \
-D BUILD_EXAMPLES=ON -D BUILD_opencv_python2=OFF \ 
-D BUILD_opencv_python3=ON \ 
-D WITH_FFMPEG=ON \
-D WITH_LIBV4L=ON \ 
-D WITH_GTK=ON \ 
-D WITH_OPENGL=ON \ 
-D WITH_ZLIB=ON \ 
-D BUILD_PNG=ON \ 
-D BUILD_JPEG=ON \
-D BUILD_TIFF=ON \
-D WITH_CUDA=ON \
-D WITH_OPENCL=ON \
-D ENABLE_FAST_MATH=1 \
-D CUDA_FAST_MATH=1 \
-D WITH_CUBLAS=1 \
-D WITH_LAPACK=OFF \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D PYTHON3_EXECUTABLE=$(which python3) -DPYTHON3_INCLUDE_DIR=$(python3 -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") \
-D PYTHON3_PACKAGES_PATH=$(python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") ..

* -DCUDA_ARCH_BIN=8.6 for RTX3080

$ make -j8

$ sudo make install


Errors during compile and their solution:

Error 1. unsupported GNU version! gcc versions later than 8 are not supported!

Solution: assign the older gcc version by yourself as written in the cmake command.

Error 2. fatal error: opencv2/hdf/hdf5.hpp: No such file or directory

Solution: modify the script: hdf5.cpp (/opencv_build_4.3/opencv_contrib/modules/hdf/src/)

#include <hdf5.h> => #include "/usr/include/hdf5/serial/hdf5.h"

Check:

$ python3

$ import cv2

$ count = cv2.cuda.getCudaEnabledDeviceCount()

留言

這個網誌中的熱門文章

Tuing PID parameters in QGroundcontrol (2)

Useful PX4 Parameters

Burn linux image to eMMC storage on Banana Pi M3