美文网首页
opencv 编译 cuda

opencv 编译 cuda

作者: leon_tly | 来源:发表于2022-12-05 16:11 被阅读0次

    编译环境

    1. docker 镜像 : nvcr.io/nvidia/cuda:11.2.0-cudnn8-devel-ubuntu18.04
    2. opencv版本 : 4.5.5
    3. opencv_contrib版本 : 4.5.5

    文件链接

    https://pan.baidu.com/s/1Pa7ab79dsyQ6yx0Jd-B-Kg 密码:leon

    opencv-4.5.5.zip
    opencv_contrib-4.5.5.zip
    download.zip 里面是下载过程中下载失败的文件,需要手动将里面的放在对应文件夹下并重命名

    编译步骤

    1. 文件准备
    unzip opencv-4.5.5.zip
    unzip opencv_contrib-4.5.5.zip
    mv opencv_contrib-4.5.5 ./opencv-4.5.5
    
    1. 依赖安装
    apt update
    apt install build-essential cmake pkg-config unzip yasm git checkinstall -y
    
    1. cmake命令
    cd opencv-4.5.5 && mkdir build && cd build
    
    cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D BUILD_TESTS=OFF \
    -D BUILD_PERF_TESTS=OFF \
    -D BUILD_EXAMPLES=OFF \
    -D BUILD_opencv_apps=OFF \
    -D BUILD_PNG=ON \
    -D BUILD_JPEG=ON \
    -D BUILD_TIFF=ON \
    -D BUILD_WEBP=ON \
    -D OpenJPEG=ON \
    -D BUILD_OPENEXR=ON \
    -D OPENCV_GENERATE_PKGCONFIG=ON \
    -D OPENCV_EXTRA_MODULES_PATH=/workspace/opencv-4.5.5/opencv_contrib-4.5.5/modules \
    -D WITH_CUDA=ON \
    -D WITH_CUDNN=ON \
    -D BUILD_PROTOBUF=ON \
    -D OPENCV_DNN_CUDA=ON \
    -D CUDA_FAST_MATH=ON \
    -D CUDA_ARCH_BIN='7.5,7.0,6.1' \
    -D WITH_CUBLAS=ON \
    -D CUDNN_LIBRARY=/usr/lib/x86_64-linux-gnu/libcudnn.so.8.1.1 \
    -D CUDNN_INCLUDE_DIR=/usr/include  \
    -D CUDA_CUDA_LIBRARY=/usr/lib/x86_64-linux-gnu/libcuda.so \
    -D WITH_GSTREAMER=OFF \
    -D WITH_FFMPEG=OFF \
    -D WITH_QT=OFF \
    -D WITH_GTK=OFF \
    -D WITH_FFMPEG=OFF \
    -D BUILD_JAVA=OFF \
    -D WITH_1394=OFF ..
    

    在cmake的过程中由于网络原因可能存在文件下载失败的情况。
    可以将已经下载好的文件放在.cache对应的文件夹下,并重命名。
    CUDA_ARCH_BIN 显卡对应能力,可填写多个,但是需要cuda支持,可以根据下面这个网址查询https://developer.nvidia.com/zh-cn/cuda-gpus#compute
    编译静态库添加 -D BUILD_SHARED_LIBS=OFF
    不需要编译的最好都填OFF,加快编译速度
    opencv cmake 配置选项网址:OpenCV: OpenCV configuration options reference

    1. cmake输出
    -- General configuration for OpenCV 4.5.5 =====================================
    --   Version control:               unknown
    -- 
    --   Extra modules:
    --     Location (extra):            /workspace/opencv-4.5.5/opencv_contrib-4.5.5/modules
    --     Version control (extra):     unknown
    -- 
    --   Platform:
    --     Timestamp:                   2022-12-06T07:59:55Z
    --     Host:                        Linux 5.10.16.3-microsoft-standard-WSL2 x86_64
    --     CMake:                       3.10.2
    --     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 (16 files):         + SSSE3 SSE4_1
    --       SSE4_2 (1 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
    --       FP16 (0 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
    --       AVX (4 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
    --       AVX2 (31 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
    --       AVX512_SKX (5 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 7.5.0)
    --     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 -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 -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 -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 -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:                      NO
    --     Precompiled headers:         NO
    --     Extra dependencies:          m pthread cudart_static dl rt nppc nppial nppicc nppidei nppif nppig nppim nppist nppisu nppitc npps cublas cudnn cufft -L/usr/local/cuda/lib64 -L/usr/lib/x86_64-linux-gnu
    --     3rdparty dependencies:
    -- 
    --   OpenCV modules:
    --     To be built:                 aruco barcode bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev datasets dnn dnn_objdetect dnn_superres dpm face features2d flann fuzzy gapi hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot quality rapid reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking video videoio videostab wechat_qrcode xfeatures2d ximgproc xobjdetect xphoto
    --     Disabled:                    world
    --     Disabled by dependency:      -
    --     Unavailable:                 alphamat cvv freetype hdf java julia matlab ovis python2 python3 sfm ts viz
    --     Applications:                -
    --     Documentation:               NO
    --     Non-free algorithms:         NO
    -- 
    --   GUI:                           NONE
    --     VTK support:                 NO
    -- 
    --   Media I/O: 
    --     ZLib:                        build (ver 1.2.11)
    --     JPEG:                        build-libjpeg-turbo (ver 2.1.2-62)
    --     WEBP:                        build (ver encoder: 0x020f)
    --     PNG:                         build (ver 1.6.37)
    --     TIFF:                        build (ver 42 - 4.2.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:
    --     v4l/v4l2:                    YES (linux/videodev2.h)
    -- 
    --   Parallel framework:            pthreads
    -- 
    --   Trace:                         YES (with Intel ITT)
    -- 
    --   Other third-party libraries:
    --     Intel IPP:                   2020.0.0 Gold [2020.0.0]
    --            at:                   /workspace/opencv-4.5.5/build/3rdparty/ippicv/ippicv_lnx/icv
    --     Intel IPP IW:                sources (2020.0.0)
    --               at:                /workspace/opencv-4.5.5/build/3rdparty/ippicv/ippicv_lnx/iw
    --     VA:                          NO
    --     Lapack:                      NO
    --     Eigen:                       NO
    --     Custom HAL:                  NO
    --     Protobuf:                    build (3.19.1)
    -- 
    --   NVIDIA CUDA:                   YES (ver 11.2, CUFFT CUBLAS FAST_MATH)
    --     NVIDIA GPU arch:             75 70 61
    --     NVIDIA PTX archs:
    -- 
    --   cuDNN:                         YES (ver 8.1.1)
    -- 
    --   OpenCL:                        YES (no extra features)
    --     Include path:                /workspace/opencv-4.5.5/3rdparty/include/opencl/1.2
    --     Link libraries:              Dynamic load
    -- 
    --   Python (for build):            NO
    -- 
    --   Install to:                    /usr/local
    -- -----------------------------------------------------------------
    -- 
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /workspace/opencv-4.5.5/build
    
    1. 编译安装
    make -j$(nproc)
    make install -j$(nproc)
    

    相关文章

      网友评论

          本文标题:opencv 编译 cuda

          本文链接:https://www.haomeiwen.com/subject/bmobfdtx.html