zoukankan      html  css  js  c++  java
  • win10 vs2019 编译 opencv4.4 + pyhton3 +cuda

    20200826 更新

    opencv  4.4 cuda 10.2 

    小坑仍然若干(迷信下载,python),但总体平顺多了。漫长的编辑 2小时。

    vs2019

    也就是所谓的vc16. 要检测是否安装了完整的C++功能和cmake支持,用vs 的installer可以选上。

    否则cmake的configure都会报错。

    1 下载

    下载opencv和opencv_contrb 直接从github上下载:

    https://github.com/opencv/opencv/archive/master.zip

    https://github.com/opencv/opencv_contrib/archive/master.zip

    遇到下载不了的,就迷信上网:

    ffmpeg ippicv xfeatures2d保存到

    /build/downloads 相应文件夹里

    face_landmark_model.dat 下载到

    /build/testdatacvface

    具体下载参考下面

    20191231更新:

    FFMPEG: Download: ffmpeg_version.cmake

    Try 1 failed

    参考 https://www.cnblogs.com/huluwa508/p/10142718.html

    cd 到

     XXXopencv-master.cacheffmpeg

    发现

    2个dll下载好了

    但是.cmake文件下载不到

    ad57c038ba34b868277ccbe6dd0f9602-ffmpeg_version.cmake

    而cmake的下载地址,根据

    XXXopencv-masteruildCMakeDownloadLog.txt

    #do_copy "ffmpeg_version.cmake" "ad57c038ba34b868277ccbe6dd0f9602" "https://raw.githubusercontent.com/opencv/opencv_3rdparty/a66a24e9f410ae05da4baeeb8b451912664ce49c/ffmpeg/ffmpeg_version.cmake" "D:/soft/dev/opencv/opencv-master/build/3rdparty/ffmpeg"
    #missing "D:/soft/dev/opencv/opencv-master/build/3rdparty/ffmpeg/ffmpeg_version.cmake"

    直接用科学方法打开标红的链接,发现只是个纯文本文件

    set(FFMPEG_libavcodec_FOUND 1)
    set(FFMPEG_libavformat_FOUND 1)
    set(FFMPEG_libavutil_FOUND 1)
    set(FFMPEG_libswscale_FOUND 1)
    set(FFMPEG_libavresample_FOUND 1)

    set(FFMPEG_libavcodec_VERSION 58.54.100)
    set(FFMPEG_libavformat_VERSION 58.29.100)
    set(FFMPEG_libavutil_VERSION 56.31.100)
    set(FFMPEG_libswscale_VERSION 5.5.100)
    set(FFMPEG_libavresample_VERSION 4.0.0)

    直接复制内容,粘贴到 体积为0的cmake文件ad57c038ba34b868277ccbe6dd0f9602-ffmpeg_version.cmake 中,保存完事。

    2 confiure

    编译选项:

    NONFREE必须开,否则即使下载的opencv_contrib也不包含sift等等nonfree库了

    cuda:

    参考 https://www.jianshu.com/p/aa8455fcc672

    选上

    BUILD_opencv_world
    WITH_CUDA
    WITH_CUDNN

    修改 CUDA_ARCH_BIN

    这个针对不同计算能力的GPU,编译不同版本,但是这部分特别慢,只能单线程编译。

    只编译自己用到的,或者可能部署用到的就可以。

    参考 https://www.cnblogs.com/xuanmanstein/p/10082831.html

    在这里查看 显卡能力 https://developer.nvidia.com/cuda-gpus

    我能用到的显卡基本也就是

    GeForce GTX 1080 Ti 6.1
    GeForce GTX 1080 6.1
    GeForce GTX 1070 6.1
    GeForce GTX 1060 6.1
    GeForce GTX 980M 5.2

    所以只保留这2个就可以啦。

    其他

    基本上多点几次Configure,直到不报错就OK。

    如果报warning:

    CMake Warning at cmake/OpenCVGenSetupVars.cmake:54 (message):   

    CONFIGURATION IS NOT SUPPORTED: validate setupvars script in install   directory Call Stack (most recent call first)

    去掉这个编译选项,应该没啥用

    python3路径现在已经能自动识别

    python3的路径一个一个补上:注意library 很迷惑,有python3.lib和 .a的。注意区别

     

    其他要注意的也就是这些了,那个OPENCV_PYTHON3_VERSION没啥用,选上好像就编译cv2.pyd不过了。保持空就可以。

    然后Generate,然后进vs2017,"ALL_BUILD"  右键"生成",经过漫长编译,如果正常,应该全都编译成功。之前因为python编译不过,卡了半天。

    然后“INSTALL” “生成”,此时产生

    opencv-4.4.0uildinstall 文件夹

    D:opencvopencv-4.4.0uildinstallx64vc16in

    添加到系统环境变量。

    保证opencv_world440.dll能被 搜索到(这个直接快300M了。。。)。这步很重要

    3手动安装opencv_python

    但C:Program FilesPython38Libsite-packages下仍然没有看见cv2.pyd

    想起应该是win10加强了C盘权限的管理,进命令行都得用管理员权限了。

    那么:直接用管理员权限启动PowerShell,cd到之前设置的 opencv的build路径(我给设置了D:softdevopencvuild)

    cd D:softdevopencvuildinstallpython_loader

    要用develop来安装,不是常用的install否则会报错

    ImportError: ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.

    https://github.com/opencv/opencv/issues/13202

    python setup.py develop

    如果C:Program FilesPython38Libsite-packages还是没有cv2.pyd 

    那就去

    D:opencvopencv-4.4.0uildlibpython3Release

    把cv2.cp38-win_amd64.pyd 手工改名成 cv2.pyd

    然后复制到

    C:Program FilesPython38Libsite-packages

     然后就能又在py上使用sift了  在python环境里查看信息

    >>> import cv2
    >>> print(cv2.getBuildInformation())

    General configuration for OpenCV 4.4.0 =====================================
    Version control: unknown

    Extra modules:
    Location (extra): D:/opencv/opencv_contrib-4.4.0/modules
    Version control (extra): unknown

    Platform:
    Timestamp: 2020-08-26T01:44:32Z
    Host: Windows 10.0.19041 AMD64
    CMake: 3.18.2
    CMake generator: Visual Studio 16 2019
    CMake build tool: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/MSBuild/Current/Bin/MSBuild.exe
    MSVC: 1927

    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: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe (ver 19.27.29111.0)
    C++ flags (Release): /DWIN32 /D_WINDOWS /W4 /GR /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /fp:precise /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MP /MD /O2 /Ob2 /DNDEBUG
    C++ flags (Debug): /DWIN32 /D_WINDOWS /W4 /GR /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /fp:precise /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MP /MDd /Zi /Ob0 /Od /RTC1
    C Compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.27.29110/bin/Hostx64/x64/cl.exe
    C flags (Release): /DWIN32 /D_WINDOWS /W3 /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /fp:precise /MP /MD /O2 /Ob2 /DNDEBUG
    C flags (Debug): /DWIN32 /D_WINDOWS /W3 /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /fp:precise /MP /MDd /Zi /Ob0 /Od /RTC1
    Linker flags (Release): /machine:x64 /INCREMENTAL:NO
    Linker flags (Debug): /machine:x64 /debug /INCREMENTAL
    ccache: NO
    Precompiled headers: NO
    Extra dependencies: cudart_static.lib nppc.lib nppial.lib nppicc.lib nppicom.lib nppidei.lib nppif.lib nppig.lib nppim.lib nppist.lib nppisu.lib nppitc.lib npps.lib cublas.lib cudnn.lib cufft.lib -LIBPATH:C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.2/lib/x64
    3rdparty dependencies:

    OpenCV modules:
    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 dnn_superres dpm face features2d flann fuzzy gapi hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor 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 world xfeatures2d ximgproc xobjdetect
    Disabled: xphoto
    Disabled by dependency: -
    Unavailable: alphamat cnn_3dobj cvv freetype hdf java js julia matlab ovis python2 python2 sfm viz
    Applications: tests perf_tests examples apps
    Documentation: NO
    Non-free algorithms: YES

    Windows RT support: NO

    GUI:
    Win32 UI: YES
    VTK support: NO

    Media I/O:
    ZLib: build (ver 1.2.11)
    JPEG: build-libjpeg-turbo (ver 2.0.5-62)
    WEBP: build (ver encoder: 0x020f)
    PNG: build (ver 1.6.37)
    TIFF: build (ver 42 - 4.0.10)
    JPEG 2000: build Jasper (ver 1.900.1)
    OpenEXR: build (ver 2.3.0)
    HDR: YES
    SUNRASTER: YES
    PXM: YES
    PFM: YES

    Video I/O:
    DC1394: NO
    FFMPEG: YES (prebuilt binaries)
    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
    DirectShow: YES
    Media Foundation: YES
    DXVA: YES

    Parallel framework: Concurrency

    Trace: YES (with Intel ITT)

    Other third-party libraries:
    Intel IPP: 2020.0.0 Gold [2020.0.0]
    at: D:/opencv/opencv-4.4.0/build/3rdparty/ippicv/ippicv_win/icv
    Intel IPP IW: sources (2020.0.0)
    at: D:/opencv/opencv-4.4.0/build/3rdparty/ippicv/ippicv_win/iw
    Lapack: NO
    Eigen: NO
    OpenVX: NO
    Custom HAL: NO
    Protobuf: build (3.5.1)

    NVIDIA CUDA: YES (ver 10.2, CUFFT CUBLAS)
    NVIDIA GPU arch: 52 61
    NVIDIA PTX archs:

    cuDNN: YES (ver 7.6.5)

    OpenCL: YES (NVD3D11)
    Include path: D:/opencv/opencv-4.4.0/3rdparty/include/opencl/1.2
    Link libraries: Dynamic load

    Python 3:
    Interpreter: C:/Program Files/Python38/python.exe (ver 3.8.5)
    Libraries: C:/Program Files/Python38/libs/python38.lib (ver 3.8.5)
    numpy: C:/Program Files/Python38/lib/site-packages/numpy/core/include (ver 1.18.5)
    install path: C:/Program Files/Python38/Lib/site-packages/cv2/python-3.8

    Python (for build): C:/Program Files/Python38/python.exe

    Java:
    ant: NO
    JNI: NO
    Java wrappers: NO
    Java tests: NO

    Install to: D:/opencv/opencv-4.4.0/build/install
    -----------------------------------------------------------------

    编译完成。

  • 相关阅读:
    angularJs项目实战!02:前端的页面分解与组装
    angularJs项目实战!01:模块划分和目录组织
    django admin 导出数据简单示例
    django 学习之model操作(想细化)
    6.11大杂烩。。
    InlineModelAdmin对象的学习
    django-salmonella的使用
    python 保留两位小数
    Django 时间与时区设置问题
    Django学习
  • 原文地址:https://www.cnblogs.com/xuanmanstein/p/10040119.html
Copyright © 2011-2022 走看看