This is the 12th day of my participation in the August More Text Challenge. For details, see:August is more challenging

Software and Hardware Environment

  • Ubuntu 18.04 64 – bit
  • NVIDIA GTX 1070Ti 8G
  • Anaconda with python 3.6
  • Opencv rule 3.4.3
  • Cuda 9.0

Install the graphics driver and CUDA

Under the ubuntu installation method of post has introduced before, go here, please refer to the xugaoxiang.com/2019/12/13/…

Compile the opencv

My python environment anaconda3 here, if you are not very familiar with, you can reference this article xugaoxiang.com/2019/12/08/…

The mkdir opencv_cuda CD opencv_cuda git clone https://github.com/opencv/opencv.git CD opencv git checkout - b rule 3.4.3 CD.. Git clone https://github.com/opencv/opencv_contrib.git CD opencv_contrib git checkout - b rule 3.4.3 CD.. /opencv mkdir build CD build # If you are not using anaconda, The CMAKE_INSTALL_PREFIX parameter can be set to /usr/local cmake -d CMAKE_BUILD_TYPE=RELEASE -d INSTALL_C_EXAMPLES=ON -d INSTALL_PYTHON_EXAMPLES=ON -D OPENCV_EXTRA_MODULES_PATH=.. /.. /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 -DCMAKE_INSTALL_PREFIX=$(python -c "import sys; print(sys.prefix)") -DPYTHON3_EXECUTABLE=$(which python) -DPYTHON3_INCLUDE_DIR=$(python -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())") -DPYTHON3_PACKAGES_PATH=$(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())") .. make -j8 sudo make install sudo ldconfigCopy the code

Take a look at the CUDA and Python3 related output after cmake

-- NVIDIA CUDA: YES (ver 9.0, CUFFT CUBLAS NVCUVID) -- NVIDIA GPU arch: 62 -- NVIDIA PTX archs: -- -- OpenCL: YES (no extra features) -- Include path: / home/longjing/Work/opencv_cuda/opencv / 3 rdparty/include/opencl / 1.2 - Link libraries: Dynamic load - Python 3: Interpreter: / home/longjing anaconda3 / bin/python3 (ver 3.6.6) - Libraries: NO - numpy: / home/longjing anaconda3 / lib/python3.6 / site - packages/numpy/core/include (ver 1.12.1) - packages path: Lib/python3.6 / site - packagesCopy the code

I have the following error in the make process

[ 24%] Generating perf_precomp.hpp.gch/opencv_perf_video_Release.gch [ 24%] Built target pch_Generate_opencv_stitching [  24%] Generating test_precomp.hpp.gch/opencv_test_videostab_Release.gch [ 24%] Built target pch_Generate_opencv_test_stitching [ 24%] Built target pch_Generate_opencv_video [ 24%] Generating perf_precomp.hpp.gch/opencv_perf_superres_Release.gch [ 24%] Generating precomp.hpp.gch/opencv_superres_Release.gch [ 24%] Built target pch_Generate_opencv_test_video [ 24%] Generating test_precomp.hpp.gch/opencv_test_superres_Release.gch  [ 24%] Built target pch_Generate_opencv_perf_stitching [ 24%] Built target pch_Generate_opencv_perf_video [ 24%] Built target pch_Generate_opencv_videostab [ 24%] Building NVCC (Device) object modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/cuda_compile_1_generated_gpu_mat.cu.o /home/longjing/Work/opencv_cuda/opencv/modules/core/src/cuda/gpu_mat.cu:47:2: error: #error "opencv_cudev is required" #error "opencv_cudev is required" ^ CMake Error at cuda_compile_1_generated_gpu_mat.cu.o.Release.cmake:219 (message): Error generating /home/longjing/Work/opencv_cuda/opencv/build/modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/./cuda_compile_1_genera ted_gpu_mat.cu.o modules/core/CMakeFiles/opencv_core.dir/build.make:63: recipe for target 'modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/cuda_compile_1_generated_gpu_mat.cu.o' failed make[2]: *** [modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/cuda_compile_1_generated_gpu_mat.cu.o] Error 1 CMakeFiles/Makefile2:1664: recipe for target 'modules/core/CMakeFiles/opencv_core.dir/all' failed make[1]: *** [modules/core/CMakeFiles/opencv_core.dir/all] Error 2 make[1]: *** Waiting for unfinished jobs.... [ 24%] Built target pch_Generate_opencv_superres [ 24%] Built target pch_Generate_opencv_perf_superres [ 24%] Built target pch_Generate_opencv_test_videostab [ 24%] Built target pch_Generate_opencv_test_superres Makefile:162: recipe for target 'all' failed make: *** [all] Error 2Copy the code

OPENCV_EXTRA_MODULES_PATH: Extra Modules: Extra modules: Extra modules: Extra modules: Extra modules When adding or removing a feature, it is recommended that you take a close look at the information after cmake and make sure it is correct.

-- HDF5: Using hdf5 compiler wrapper to determine C configuration -- Module opencv_ovis disabled because OGRE3D was not found -- No preference for use of exported gflags CMake configuration set, and no hints for include/library directories provided. Defaulting to preferring an installed/exported gflags CMake configuration if available. -- Failed to find installed gflags CMake configuration, searching for gflags build directories exported with CMake. -- Failed to find gflags - Failed to find an installed/exported CMake configuration for gflags, will perform search for installed gflags components. -- Failed to find gflags - Could not find gflags include directory,  set GFLAGS_INCLUDE_DIR to directory containing gflags/gflags.h -- Failed to find glog - Could not find glog include directory, set GLOG_INCLUDE_DIR to directory containing glog/logging.h -- Module opencv_sfm disabled because the following dependencies are not found: Eigen Glog/Gflags -- Checking for module 'tesseract' -- No package 'tesseract' found -- Tesseract: NO -- HDF5: Using hdf5 compiler wrapper to determine C configuration -- Registering hook 'INIT_MODULE_SOURCES_opencv_dnn': /home/longjing/xgx/opencv_cuda/opencv/modules/dnn/cmake/hooks/INIT_MODULE_SOURCES_opencv_dnn.cmake CMake Error at modules/dnn/CMakeLists.txt:97 (message): CUDA Backend for DNN module requires CC 5.3 or higher. Please remove unsupported Architectures from CUDA_ARCH_BIN option. -- Configuring incomplete, errors occurred! See also "/home/longjing/xgx/opencv_cuda/opencv/build/CMakeFiles/CMakeOutput.log". See also "/home/longjing/xgx/opencv_cuda/opencv/build/CMakeFiles/CMakeError.log".Copy the code

In the build/CMakeCache. TXT file, delete CUDA_ARCH_BIN.

[ 37%] Building NVCC (Device) object modules/cudafilters/CMakeFiles/cuda_compile_1.dir/src/cuda/cuda_compile_1_generated_median_filter.cu.o [ 37%] Linking CXX executable .. /.. /bin/example_phase_unwrapping_unwrap .. /.. /lib/libopencv_imgcodecs.so.4.0.0: undefined reference to 'TIFFReadDirectory@LIBTIFF_4.0'.. /.. /lib/libopencv_imgcodecs.so.4.0.0: undefined reference to 'TIFFWriteEncodedStrip@LIBTIFF_4.0'.. /.. /lib/libopencv_imgcodecs.so.4.0.0: undefined reference to 'TIFFIsTiled@LIBTIFF_4.0'.. /.. /lib/libopencv_imgcodecs.so.4.0.0: undefined reference to 'TIFFOpen@LIBTIFF_4.0'.. /.. /lib/libopencv_imgcodecs.so.4.0.0: undefined reference to 'TIFFReadEncodedStrip@LIBTIFF_4.0'.. /.. /lib/libopencv_imgcodecs.so.4.0.0: undefined reference to 'TIFFSetField@LIBTIFF_4.0'.. /.. /lib/libopencv_imgcodecs.so.4.0.0: undefined reference to 'TIFFWriteScanline@LIBTIFF_4.0'.. /.. /lib/libopencv_imgcodecs.so.4.0.0: undefined reference to '_TIFFfree@LIBTIFF_4.0'.. /.. /lib/libopencv_imgcodecs.so.4.0.0: undefined reference to 'TIFFGetField@LIBTIFF_4.0'.. /.. /lib/libopencv_imgcodecs.so.4.0.0: undefined reference to 'TIFFScanlineSize@LIBTIFF_4.0'.. /.. /lib/libopencv_imgcodecs.so.4.0.0: undefined reference to 'TIFFNumberOfStrips@LIBTIFF_4.0'.. /.. /lib/libopencv_imgcodecs.so.4.0.0: undefined reference to 'TIFFWriteDirectory@LIBTIFF_4.0'.. /.. /lib/libopencv_imgcodecs.so.4.0.0: undefined reference to 'TIFFSetWarningHandler@LIBTIFF_4.0'.. /.. /lib/libopencv_imgcodecs.so.4.0.0: undefined reference to '_TIFFmalloc@LIBTIFF_4.0'.. /.. /lib/libopencv_imgcodecs.so.4.0.0: undefined reference to 'TIFFSetErrorHandler@LIBTIFF_4.0'.. /.. /lib/libopencv_imgcodecs.so.4.0.0: undefined reference to 'TIFFReadEncodedTile@LIBTIFF_4.0'.. /.. /lib/libopencv_imgcodecs.so.4.0.0: undefined reference to 'TIFFReadRGBATile@LIBTIFF_4.0'.. /.. /lib/libopencv_imgcodecs.so.4.0.0: undefined reference to 'TIFFReadScanline@LIBTIFF_4.0'.. /.. /lib/libopencv_imgcodecs.so.4.0.0: undefined reference to 'TIFFClose@LIBTIFF_4.0'.. /.. /lib/libopencv_imgcodecs.so.4.0.0: undefined reference to 'TIFFRGBAImageOK@LIBTIFF_4.0'.. /.. /lib/libopencv_imgcodecs.so.4.0.0: undefined reference to 'TIFFClientOpen@LIBTIFF_4.0'.. /.. /libopencv_imgcodecs.so.4.0.0: undefined reference to 'TIFFReadRGBAStrip@LIBTIFF_4.0' collect2: error: ld returned 1 exit status modules/phase_unwrapping/CMakeFiles/example_phase_unwrapping_unwrap.dir/build.make:101: recipe for target 'bin/example_phase_unwrapping_unwrap' failed make[2]: *** [bin/example_phase_unwrapping_unwrap] Error 1 CMakeFiles/Makefile2:5054: recipe for target 'modules/phase_unwrapping/CMakeFiles/example_phase_unwrapping_unwrap.dir/all' failed make[1]: *** [modules/phase_unwrapping/CMakeFiles/example_phase_unwrapping_unwrap.dir/all] Error 2 make[1]: *** Waiting for unfinished jobs....Copy the code

Conda install libtiff

conda install -c anaconda libtiff
Copy the code

Due to network reasons, some packages may not be downloaded successfully during the compilation process, such as ippicv_2019_lnx_intel64_general_20180723.tgz. In this case, you can solve this problem, first in the source directory

grep "ippicv_2019_lnx_intel64_general_20180723.tgz" . -r -n
Copy the code

Command output

(base) longjing@ai:~/xgx/opencv_cuda/opencv$ grep "ippicv_2019_lnx_intel64_general_20180723.tgz" . -r -n ./3rdparty/ippicv/ippicv.cmake:21: set(OPENCV_ICV_NAME "ippicv_2019_lnx_intel64_general_20180723.tgz") ./build/CMakeDownloadLog.txt:2:#do_unpack "ippicv_2019_lnx_intel64_general_20180723.tgz" "c0bd78adb4156bbf552c1dfe90599607" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/32e315a5b106a7b89dbed51c28f8120a48b368b4/ippicv/ippicv_2019_ln x_intel64_general_20180723.tgz" "/home/longjing/xgx/opencv_cuda/opencv/build/3rdparty/ippicv" ./build/CMakeDownloadLog.txt:3:#cmake_download "/home/longjing/xgx/opencv_cuda/opencv/.cache/ippicv/c0bd78adb4156bbf552c1dfe90599607-ippicv_2019_lnx_intel64_general_20 180723.tgz" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/32e315a5b106a7b89dbed51c28f8120a48b368b4/ippicv/ippicv_2019_ln x_intel64_general_20180723.tgz" ./build/download_with_wget.sh:1:mkdir -p $(dirname /home/longjing/xgx/opencv_cuda/opencv/.cache/ippicv/c0bd78adb4156bbf552c1dfe90599607-ippicv_2019_lnx_intel64_general_201 80723.tgz) && wget -O "/home/longjing/xgx/opencv_cuda/opencv/.cache/ippicv/c0bd78adb4156bbf552c1dfe90599607-ippicv_2019_lnx_intel64_general_20 180723.tgz" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/32e315a5b106a7b89dbed51c28f8120a48b368b4/ippicv/ippicv_2019_ln x_intel64_general_20180723.tgz" ./build/download_with_curl.sh:1:curl --create-dirs --output "/home/longjing/xgx/opencv_cuda/opencv/.cache/ippicv/c0bd78adb4156bbf552c1dfe90599607-ippicv_2019_lnx_intel64_general_20 180723.tgz" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/32e315a5b106a7b89dbed51c28f8120a48b368b4/ippicv/ippicv_2019_ln x_intel64_general_20180723.tgz"Copy the code

Can be seen in the output information raw.githubusercontent.com/opencv/open scripts from address… We can manually go to wget and copy the files to the corresponding directory ourselves. Such as the directory/home/here longjing/XGX/opencv_cuda/opencv/cache/ippicv/c0bd78adb4156bbf552c1dfe90599607 – ippicv_2019_lnx_intel64_gene ral_20180723.tgz

validation

Import the Cv2 module to view the output information of method cv2.getBuildInformation()

Longjing @ FR: ~ / Work/opencv_cuda opencv/build $ipython Python 3.6.6 | said by conda - forge | (default, Oct 12, 2018, 14:08:43) Type 'copyright', 'Credits' or 'license' for more Information IPython 7.0.1 -- An enhanced Interactive Python. Type '? ' for help. In [1]: import cv2 --------------------------------------------------------------------------- ImportError Traceback (most recent call last) <ipython-input-1-c8ec22b3e787> in <module>() ----> 1 import cv2 ImportError: The/usr/lib/x86_64 - - the gnu/Linux libatk - 1.0 so. 0: undefined symbol: g_log_structured_standardCopy the code

Solution:

To save trouble, I updated Anaconda directly to prevent similar errors from appearing again and again

conda update --all
Copy the code

There are also some problems in my environment, such as libhdf5, which can be solved by installing conda install *.

Python 3.6.6 | packaged by conda-forge | (default, Oct 12 2018, 14:08:43) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.0.1 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import cv2                                                                                                                                                                                                 

In [2]: cv2.getBuildInformation()                                                                                                                                                                                  
Out[2]: '\nGeneral configuration for OpenCV 4.0.0-pre =====================================\n  Version control:               4.0.0-beta-28-gdbed39a93\n\n  Extra modules:\n    Location (extra):            /home/longjing/Work/opencv_cuda/opencv_contrib/modules\n    Version control (extra):     4.0.0-beta-4-gfd63e177\n\n  Platform:\n    Timestamp:                   2018-10-26T02:12:24Z\n    Host:                        Linux 4.15.0-33-generic x86_64\n    CMake:                       3.10.2\n    CMake generator:             Unix Makefiles\n    CMake build tool:            /usr/bin/make\n    Configuration:               RELEASE\n\n  CPU/HW features:\n    Baseline:                    SSE SSE2 SSE3\n      requested:                 SSE3\n    Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX\n      requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX\n      SSE4_1 (5 files):          + SSSE3 SSE4_1\n      SSE4_2 (2 files):          + SSSE3 SSE4_1 POPCNT SSE4_2\n      FP16 (1 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX\n      AVX (6 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX\n      AVX2 (11 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2\n      AVX512_SKX (1 files):      + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_SKX\n\n  C/C++:\n    Built as dynamic libs?:      YES\n    C++ Compiler:                /usr/local/cuda-9.0/bin/c++  (ver 5.5.0)\n    C++ flags (Release):         -fsigned-char -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 -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffast-math -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG\n    C++ flags (Debug):           -fsigned-char -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 -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffast-math -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG\n    C Compiler:                  /usr/local/cuda-9.0/bin/cc\n    C flags (Release):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffast-math -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG\n    C flags (Debug):             -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffast-math -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG\n    Linker flags (Release):      \n    Linker flags (Debug):        \n    ccache:                      NO\n    Precompiled headers:         YES\n    Extra dependencies:          m pthread cudart_static -lpthread dl rt nppc nppial nppicc nppicom nppidei nppif nppig nppim nppist nppisu nppitc npps cublas cufft -L/usr/local/cuda-9.0/lib64 -L/usr/lib/x86_64-linux-gnu\n    3rdparty dependencies:\n\n  OpenCV modules:\n    To be built:                 aruco bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev datasets dnn dnn_objdetect dpm face features2d flann freetype fuzzy gapi hdf hfs highgui img_hash imgcodecs imgproc java_bindings_generator line_descriptor ml objdetect optflow phase_unwrapping photo plot python3 python_bindings_generator reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab xfeatures2d ximgproc xobjdetect xphoto\n    Disabled:                    python2 world\n    Disabled by dependency:      -\n    Unavailable:                 cnn_3dobj cvv java js matlab ovis sfm viz\n    Applications:                tests perf_tests examples apps\n    Documentation:               NO\n    Non-free algorithms:         NO\n\n  GUI: \n    GTK+:                        YES (ver 3.22.30)\n      GThread :                  YES (ver 2.56.1)\n      GtkGlExt:                  NO\n    OpenGL support:              NO\n    VTK support:                 NO\n\n  Media I/O: \n    ZLib:                        /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.11)\n    JPEG:                        /usr/lib/x86_64-linux-gnu/libjpeg.so (ver 80)\n    WEBP:                        /usr/lib/x86_64-linux-gnu/libwebp.so (ver encoder: 0x020e)\n    PNG:                         /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.6.34)\n    TIFF:                        build (ver 42 - 4.0.9)\n    JPEG 2000:                   /home/longjing/anaconda3/lib/libjasper.so (ver 2.0.14)\n    OpenEXR:                     /usr/lib/x86_64-linux-gnu/libImath.so /usr/lib/x86_64-linux-gnu/libIlmImf.so /usr/lib/x86_64-linux-gnu/libIex.so /usr/lib/x86_64-linux-gnu/libHalf.so /usr/lib/x86_64-linux-gnu/libIlmThread.so (ver 2.2.0)\n    HDR:                         YES\n    SUNRASTER:                   YES\n    PXM:                         YES\n    PFM:                         YES\n\n  Video I/O:\n    DC1394:                      YES (ver 2.2.5)\n    FFMPEG:                      YES\n      avcodec:                   YES (ver 58.18.100)\n      avformat:                  YES (ver 58.12.100)\n      avutil:                    YES (ver 56.14.100)\n      swscale:                   YES (ver 5.1.100)\n      avresample:                YES (ver 3.7.0)\n    GStreamer:                   \n      base:                      YES (ver 1.14.1)\n      video:                     YES (ver 1.14.1)\n      app:                       YES (ver 1.14.1)\n      riff:                      YES (ver 1.14.1)\n      pbutils:                   YES (ver 1.14.1)\n    libv4l/libv4l2:              1.14.2 / 1.14.2\n    v4l/v4l2:                    linux/videodev.h linux/videodev2.h\n\n  Parallel framework:            pthreads\n\n  Trace:                         YES (with Intel ITT)\n\n  Other third-party libraries:\n    Intel IPP:                   2017.0.3 [2017.0.3]\n           at:                   /home/longjing/Work/opencv_cuda/opencv/build/3rdparty/ippicv/ippicv_lnx\n    Intel IPP IW:                sources (2017.0.3)\n              at:                /home/longjing/Work/opencv_cuda/opencv/build/3rdparty/ippicv/ippiw_lnx\n    Eigen:                       NO\n    Custom HAL:                  NO\n    Protobuf:                    build (3.5.1)\n\n  NVIDIA CUDA:                   YES (ver 9.0, CUFFT CUBLAS NVCUVID FAST_MATH)\n    NVIDIA GPU arch:             30 35 37 50 52 60 61 70\n    NVIDIA PTX archs:\n\n  OpenCL:                        YES (no extra features)\n    Include path:                /home/longjing/Work/opencv_cuda/opencv/3rdparty/include/opencl/1.2\n    Link libraries:              Dynamic load\n\n  Python 3:\n    Interpreter:                 /home/longjing/anaconda3/bin/python (ver 3.6.6)\n    Libraries:                   /home/longjing/anaconda3/lib/libpython3.6m.so (ver 3.6.6)\n    numpy:                       /home/longjing/anaconda3/lib/python3.6/site-packages/numpy/core/include (ver 1.15.3)\n    packages path:               /home/longjing/anaconda3/lib/python3.6/site-packages\n\n  Python (for build):            /usr/bin/python2.7\n    Pylint:                      /home/longjing/anaconda3/bin/pylint (ver: 3.6.6, checks: 162)\n\n  Java:                          \n    ant:                         NO\n    JNI:                         /usr/lib/jvm/java-8-openjdk-amd64/include /usr/lib/jvm/java-8-openjdk-amd64/include/linux /usr/lib/jvm/java-8-openjdk-amd64/include\n    Java wrappers:               NO\n    Java tests:                  NO\n\n  Install to:                    /home/longjing/anaconda3\n-----------------------------------------------------------------\n\n'   
Copy the code

From the above output, you can see that CUDA is enabled for the Cv2 module in Python.

When using OpencV for video processing, I encountered a problem

(Deep learning object detection in OpenCV:8725): gstreamer-critical **: 15:47:19.541: gst_element_get_state: assertion 'GST_IS_ELEMENT (element)' failed Unable to stop the stream: Inappropriate ioctl for Device (Deep Learning Object Detection in OpenCV:8725): GStreamer-CRITICAL **: 15:47:19.541: Inappropriate ioctl for Device (Deep Learning Object Detection in OpenCV:8725): GStreamer-CRITICAL **: 15:47:19.541: gst_element_make_from_uri: assertion 'gst_uri_is_valid (uri)' faileCopy the code

Sudo apt install ffmpeg libv4l-dev if you are using anaconda, run the following command

conda install -c conda-forge ffmpeg
Copy the code

Then verify the ffMPEG path

longjing@FR:~$ which ffmpeg 
/home/longjing/anaconda3/bin/ffmpeg
Copy the code

Finally, go to the opencv directory and re-cmake to see if ffmpeg features have been added

-- Video I/O: -- DC1394: YES (ver 2.2.5) -- FFMPEG: YES -- AVCOdec: YES (ver 58.18.100) -- AvFormat: YES (ver 58.12.100) -- avutil: YES (ver 56.14.100) -- swscale: YES (ver 5.1.100) -- avresample: YES (ver 3.7.0) -- GStreamer: -- base: YES (ver 1.14.1) -- video: YES (ver 1.14.1) -- app: YES (ver 1.14.1) -- riff: Pbutils: YES (ver 1.14.1) -- libv4l/libv4l2: 1.14.2/1.14.2 -- v4L /v4l2: linux/videodev.h linux/videodev2.hCopy the code

How to accelerate

Here is the object detection using YOLOv3 model in OpenCV as an example. You can see the basic use of Darknet for details

# YOLO V3 configuration and weights file modelConfiguration = "yolov3-voc. CFG "modelWeights = "voc.weights" # OpencV read the external model net = cv2.dnn.readNetFromDarknet(modelConfiguration, modelWeights) net.setPreferableBackend(cv2.dnn.DNN_BACKEND_CUDA) net.setPreferableTarget(cv2.dnn.DNN_TARGET_CUDA)Copy the code

The resources

  • Xugaoxiang.com/2019/12/13/…
  • Docs.opencv.org/3.4/d6/d15/…
  • www.pyimagesearch.com/2016/07/11/…
  • Stackoverflow.com/questions/5…
  • Stackoverflow.com/questions/4…