Open6

NVIDIA optical flow SDK v2.0 + OpenCV + CUDA11.3 ビルド試行

PINTOPINTO
xhost +local: && \
docker run -it --rm --gpus all \
-v `pwd`:/home/user/workdir \
-v /tmp/.X11-unix/:/tmp/.X11-unix:rw \
--device /dev/video0:/dev/video0:mwr \
--net=host \
-e XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR \
-e DISPLAY=$DISPLAY \
-e NVIDIA_DRIVER_CAPABILITIES=compute,video,utility \
--privileged \
pinto0309/opencvbuild_cuda11.3_cudnn8_ubuntu2004:latest

mkdir opencvbuild && cd opencvbuild
git clone -b 4.5.2 https://github.com/opencv/opencv.git
git clone -b 4.5.2 https://github.com/opencv/opencv_contrib.git
cd opencv && mkdir build && cd build
PINTOPINTO
apt install -y python3-dev python3-pip gcc-7 g++-7 cmake \
build-essential git pkg-config ccache libxshmfence-dev libasound2-dev \
unzip extra-cmake-modules mesa-utils libgtk-3-dev ffmpeg \
libavcodec-dev libavformat-dev libswscale-dev libtbb-dev libogre-1.9-dev \
libjpeg-dev libpng-dev libtiff5-dev x264 libxvidcore-dev yasm \
libxine2-dev libv4l-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev \
libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev \
x264 v4l-utils ffmpeg libdc1394-22 libdc1394-22-dev libtiff5-dev \
qt5-default libeigen3-dev libeigen3-doc tesseract-ocr tesseract-ocr-jpn \
vtk7 tcl-vtk7 python3-vtk7 libgflags-dev autoconf automake libtool \
autoconf-archive libleptonica-dev libtesseract-dev gphoto2 liblapacke-dev \
libgstreamer1.0-0 gstreamer1.0-tools gstreamer1.0-plugins-base \
gstreamer1.0-plugins-good gstreamer1.0-plugins-bad \
gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-doc \
gstreamer1.0-tools gstreamer1.0-x gstreamer1.0-alsa \
gstreamer1.0-gl gstreamer1.0-gtk3 gstreamer1.0-qt5 libhdf5-dev \
libatlas-base-dev gstreamer1.0-opencv libva-dev

pip3 install pip --upgrade
pip3 install onnx onnxruntime
PINTOPINTO
cmake \
-DCMAKE_BUILD_TYPE=RELEASE \
-DCMAKE_INSTALL_PREFIX=/usr/local \
-DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
-DCUDA_ARCH_BIN=8.6 \
-DCUDA_ARCH_PTX=8.6 \
-DOPENCV_GENERATE_PKGCONFIG=ON \
-DBUILD_opencv_apps=ON \
-DBUILD_opencv_calib3d=ON \
-DBUILD_opencv_core=ON \
-DBUILD_opencv_cudaarithm=ON \
-DBUILD_opencv_cudabgsegm=ON \
-DBUILD_opencv_cudacodec=ON \
-DBUILD_opencv_cudafeatures2d=ON \
-DBUILD_opencv_cudafilters=ON \
-DBUILD_opencv_cudaimgproc=ON \
-DBUILD_opencv_cudalegacy=ON \
-DBUILD_opencv_cudaobjdetect=ON \
-DBUILD_opencv_cudaoptflow=ON \
-DBUILD_opencv_cudastereo=ON \
-DBUILD_opencv_cudawarping=ON \
-DBUILD_opencv_cudev=ON \
-DBUILD_opencv_features2d=ON \
-DBUILD_opencv_flann=ON \
-DBUILD_opencv_highgui=ON \
-DBUILD_opencv_imgcodecs=ON \
-DBUILD_opencv_imgproc=ON \
-DBUILD_opencv_ml=ON \
-DBUILD_opencv_objdetect=ON \
-DBUILD_opencv_photo=ON \
-DBUILD_opencv_stitching=ON \
-DBUILD_opencv_superres=ON \
-DBUILD_opencv_ts=ON \
-DBUILD_opencv_video=ON \
-DBUILD_opencv_videoio=ON \
-DBUILD_opencv_videostab=ON \
-DWITH_1394=ON \
-DWITH_CUBLAS=ON \
-DWITH_CUDA=ON \
-DWITH_CUFFT=ON \
-DWITH_EIGEN=ON \
-DWITH_FFMPEG=ON \
-DWITH_GDAL=OFF \
-DWITH_GPHOTO2=ON \
-DWITH_GIGEAPI=ON \
-DWITH_GSTREAMER=ON \
-DWITH_GTK=ON \
-DWITH_INTELPERC=OFF \
-DWITH_IPP=ON \
-DWITH_IPP_A=OFF \
-DWITH_JASPER=ON \
-DWITH_JPEG=ON \
-DWITH_LIBV4L=ON \
-DWITH_ONNX=ON \
-DWITH_OPENCL=ON \
-DWITH_OPENCLAMDBLAS=OFF \
-DWITH_OPENCLAMDFFT=OFF \
-DWITH_OPENCL_SVM=OFF \
-DWITH_OPENEXR=ON \
-DWITH_OPENGL=ON \
-DWITH_OPENMP=OFF \
-DWITH_OPENNI=OFF \
-DWITH_PNG=ON \
-DWITH_PTHREADS_PF=OFF \
-DWITH_PVAPI=ON \
-DWITH_QT=ON \
-DWITH_TBB=ON \
-DWITH_TIFF=ON \
-DWITH_UNICAP=OFF \
-DWITH_V4L=ON \
-DWITH_VTK=ON \
-DWITH_WEBP=ON \
-DWITH_XIMEA=OFF \
-DWITH_XINE=OFF \
-DCUDA_NVCC_FLAGS=--expt-relaxed-constexpr \
-DCUDA_FAST_MATH=ON \
-DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-11.3 \
-DPYTHON_DEFAULT_EXECUTABLE=$(which python3) \
-DOPENCV_DNN_CUDA=ON \
-DENABLE_FAST_MATH=ON \
-DCUDA_FAST_MATH=ON ..
PINTOPINTO
-- General configuration for OpenCV 4.5.2 =====================================
--   Version control:               4.5.2
-- 
--   Extra modules:
--     Location (extra):            /opencvbuild/opencv_contrib/modules
--     Version control (extra):     4.5.2
-- 
--   Platform:
--     Timestamp:                   2021-06-25T16:09:21Z
--     Host:                        Linux 5.8.0-55-generic x86_64
--     CMake:                       3.16.3
--     CMake generator:             Unix Makefiles
--     CMake build tool:            /usr/bin/make
--     Configuration:               RELEASE
-- 
--   CPU/HW features:
--     Baseline:                    SSE SSE2 SSE3
--       requested:                 SSE3
--     Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
--       requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
--       SSE4_1 (17 files):         + SSSE3 SSE4_1
--       SSE4_2 (2 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
--       FP16 (1 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
--       AVX (5 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
--       AVX2 (31 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
--       AVX512_SKX (7 files):      + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX
-- 
--   C/C++:
--     Built as dynamic libs?:      YES
--     C++ standard:                11
--     C++ Compiler:                /usr/bin/c++  (ver 9.3.0)
--     C++ flags (Release):         -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
--     C++ flags (Debug):           -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
--     C Compiler:                  /usr/bin/cc
--     C flags (Release):           -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
--     C flags (Debug):             -fsigned-char -ffast-math -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG
--     Linker flags (Release):      -Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a   -Wl,--gc-sections -Wl,--as-needed  
--     Linker flags (Debug):        -Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a   -Wl,--gc-sections -Wl,--as-needed  
--     ccache:                      YES
--     Precompiled headers:         NO
--     Extra dependencies:          m pthread /usr/lib/x86_64-linux-gnu/libGL.so /usr/lib/x86_64-linux-gnu/libGLU.so cudart_static dl rt nppc nppial nppicc nppidei nppif nppig nppim nppist nppisu nppitc npps cublas cudnn cufft -L/usr/local/cuda-11.3/lib64 -L/usr/lib/x86_64-linux-gnu
--     3rdparty dependencies:
-- 
--   OpenCV modules:
--     To be built:                 alphamat aruco bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv datasets dnn dnn_objdetect dnn_superres dpm face features2d flann freetype fuzzy gapi hdf hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot python3 quality rapid reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab wechat_qrcode xfeatures2d ximgproc xobjdetect xphoto
--     Disabled:                    world
--     Disabled by dependency:      -
--     Unavailable:                 cnn_3dobj java julia matlab ovis python2 sfm viz
--     Applications:                tests perf_tests apps
--     Documentation:               NO
--     Non-free algorithms:         NO
-- 
--   GUI: 
--     QT:                          YES (ver 5.12.8)
--       QT OpenGL support:         YES (Qt5::OpenGL 5.12.8)
--     GTK+:                        NO
--     OpenGL support:              YES (/usr/lib/x86_64-linux-gnu/libGL.so /usr/lib/x86_64-linux-gnu/libGLU.so)
--     VTK support:                 NO
-- 
--   Media I/O: 
--     ZLib:                        /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.11)
--     JPEG:                        /usr/lib/x86_64-linux-gnu/libjpeg.so (ver 80)
--     WEBP:                        build (ver encoder: 0x020f)
--     PNG:                         /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.6.37)
--     TIFF:                        /usr/lib/x86_64-linux-gnu/libtiff.so (ver 42 / 4.1.0)
--     JPEG 2000:                   build (ver 2.4.0)
--     OpenEXR:                     build (ver 2.3.0)
--     HDR:                         YES
--     SUNRASTER:                   YES
--     PXM:                         YES
--     PFM:                         YES
-- 
--   Video I/O:
--     DC1394:                      YES (2.2.5)
--     FFMPEG:                      YES
--       avcodec:                   YES (58.54.100)
--       avformat:                  YES (58.29.100)
--       avutil:                    YES (56.31.100)
--       swscale:                   YES (5.5.100)
--       avresample:                YES (4.0.0)
--     GStreamer:                   NO
--     PvAPI:                       NO
--     v4l/v4l2:                    YES (linux/videodev2.h)
--     gPhoto2:                     YES
-- 
--   Parallel framework:            TBB (ver 2020.1 interface 11101)
-- 
--   Trace:                         YES (with Intel ITT)
-- 
--   Other third-party libraries:
--     Intel IPP:                   2020.0.0 Gold [2020.0.0]
--            at:                   /opencvbuild/opencv/build/3rdparty/ippicv/ippicv_lnx/icv
--     Intel IPP IW:                sources (2020.0.0)
--               at:                /opencvbuild/opencv/build/3rdparty/ippicv/ippicv_lnx/iw
--     VA:                          YES
--     Lapack:                      YES (/usr/lib/x86_64-linux-gnu/liblapack.so /usr/lib/x86_64-linux-gnu/libcblas.so /usr/lib/x86_64-linux-gnu/libatlas.so)
--     Eigen:                       YES (ver 3.3.7)
--     Custom HAL:                  NO
--     Protobuf:                    build (3.5.1)
-- 
--   NVIDIA CUDA:                   YES (ver 11.3, CUFFT CUBLAS FAST_MATH)
--     NVIDIA GPU arch:             86
--     NVIDIA PTX archs:            86
-- 
--   cuDNN:                         YES (ver 8.2.0)
-- 
--   OpenCL:                        YES (INTELVA)
--     Include path:                /opencvbuild/opencv/3rdparty/include/opencl/1.2
--     Link libraries:              Dynamic load
-- 
--   ONNX:                          NO
-- 
--   Python 3:
--     Interpreter:                 /usr/bin/python3 (ver 3.8.5)
--     Libraries:                   /usr/lib/x86_64-linux-gnu/libpython3.8.so (ver 3.8.5)
--     numpy:                       /usr/local/lib/python3.8/dist-packages/numpy/core/include (ver 1.21.0)
--     install path:                lib/python3.8/dist-packages/cv2/python-3.8
-- 
--   Python (for build):            /usr/bin/python3
-- 
--   Java:                          
--     ant:                         NO
--     JNI:                         NO
--     Java wrappers:               NO
--     Java tests:                  NO
-- 
--   Install to:                    /usr/local
-- -----------------------------------------------------------------
-- 
-- Configuring done
-- Generating done
-- Build files have been written to: /opencvbuild/opencv/build
PINTOPINTO
make -j$(nproc)
make install

/bin/bash -c 'echo "/usr/local/lib" > /etc/ld.so.conf.d/opencv.conf'
/bin/bash -c 'echo "/usr/lib" >> /etc/ld.so.conf.d/opencv.conf'
ldconfig
PINTOPINTO
python3
>>> import cv2
>>> cv2.__version__
'4.5.2'
>>> exit()