Windows中具有CUDA的python的OpenCV 3.2 [英] OpenCV 3.2 for python with CUDA in Windows

查看:88
本文介绍了Windows中具有CUDA的python的OpenCV 3.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 cmake 和Visual Studio 12(2013)(具有CUDA支持和opencv3.2 >.所有库均已成功构建,并且可以使用python运行opencv命令.

I build opencv3.2 with cmake and Visual Studio 12 (2013) with CUDA support and python3.5. All the libraries were build successfully and I can run opencv commands with python.

这是命令print(cv2.getBuildInformation())

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

  Extra modules:
    Location (extra):            D:/OpenCV/opencv_contrib/modules
    Version control (extra):     unknown

  Platform:
    Timestamp:                   2017-06-09T14:07:41Z
    Host:                        Windows 10.0.14393 AMD64
    CMake:                       3.9.0-rc2
    CMake generator:             Visual Studio 12 2013 Win64
    CMake build tool:            C:/Program Files (x86)/MSBuild/12.0/bin/MSBuild.exe
    MSVC:                        1800

  C/C++:
    Built as dynamic libs?:      YES
    C++ Compiler:                D:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/x86_amd64/cl.exe  (ver 18.0.21005.1)
    C++ flags (Release):         /DWIN32 /D_WINDOWS /W4 /GR /EHa  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /arch:AVX2 /Oi  /wd4127 /wd4251 /wd4324 /wd4275 /wd4589 /MP4  /MD /O2 /Ob2 /DNDEBUG  /Zi
    C++ flags (Debug):           /DWIN32 /D_WINDOWS /W4 /GR /EHa  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /arch:AVX2 /Oi  /wd4127 /wd4251 /wd4324 /wd4275 /wd4589 /MP4  /MDd /Zi /Ob0 /Od /RTC1
    C Compiler:                  D:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/x86_amd64/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 /arch:AVX2 /Oi    /MP4  /MD /O2 /Ob2 /DNDEBUG  /Zi
    C flags (Debug):             /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /arch:AVX2 /Oi    /MP4  /MDd /Zi /Ob0 /Od /RTC1
    Linker flags (Release):      /machine:x64  /INCREMENTAL:NO  /debug
    Linker flags (Debug):        /machine:x64  /debug /INCREMENTAL
    ccache:                      NO
    Precompiled headers:         YES
    Extra dependencies:          comctl32 gdi32 ole32 setupapi ws2_32 vfw32 C:/Users/Ramesh/Anaconda3/Library/lib/hdf5.lib cudart nppc nppi npps cublas cufft -LIBPATH:C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0/lib/x64
    3rdparty dependencies:       zlib libjpeg libwebp libpng libtiff libjasper IlmImf libprotobuf

  OpenCV modules:
    To be built:                 cudev core cudaarithm flann hdf imgproc ml reg surface_matching video cudabgsegm cudafilters cudaimgproc cudawarping dnn fuzzy imgcodecs photo shape videoio cudacodec highgui objdetect plot ts xobjdetect xphoto bgsegm bioinspired dpm face features2d line_descriptor saliency text calib3d ccalib cudafeatures2d cudalegacy cudaobjdetect cudaoptflow cudastereo datasets rgbd stereo superres tracking videostab xfeatures2d ximgproc aruco optflow phase_unwrapping stitching structured_light python3
    Disabled:                    world contrib_world
    Disabled by dependency:      -
    Unavailable:                 java python2 viz cnn_3dobj cvv freetype matlab sfm

  Windows RT support:            NO

  GUI:
    QT:                          NO
    Win32 UI:                    YES
    OpenGL support:              NO
    VTK support:                 NO

  Media I/O:
    ZLib:                        build (ver 1.2.8)
    JPEG:                        build (ver 90)
    WEBP:                        build (ver 0.3.1)
    PNG:                         build (ver 1.6.24)
    TIFF:                        build (ver 42 - 4.0.2)
    JPEG 2000:                   build (ver 1.900.1)
    OpenEXR:                     build (ver 1.7.1)
    GDAL:                        NO
    GDCM:                        NO

  Video I/O:
    Video for Windows:           YES
    DC1394 1.x:                  NO
    DC1394 2.x:                  NO
    FFMPEG:                      YES (prebuilt binaries)
      avcodec:                   YES (ver 57.64.101)
      avformat:                  YES (ver 57.56.100)
      avutil:                    YES (ver 55.34.100)
      swscale:                   YES (ver 4.2.100)
      avresample:                YES (ver 3.1.0)
    GStreamer:                   NO
    OpenNI:                      NO
    OpenNI PrimeSensor Modules:  NO
    OpenNI2:                     NO
    PvAPI:                       NO
    GigEVisionSDK:               NO
    DirectShow:                  YES
    Media Foundation:            NO
    XIMEA:                       NO
    Intel PerC:                  NO

  Parallel framework:            Concurrency

  Other third-party libraries:
    Use IPP:                     9.0.1 [9.0.1]
         at:                     D:/OpenCV/build2/3rdparty/ippicv/ippicv_win
    Use IPP Async:               NO
    Use Lapack:                  NO
    Use Eigen:                   YES (ver 3.3.3)
    Use Cuda:                    YES (ver 8.0)
    Use OpenCL:                  YES
    Use OpenVX:                  NO
    Use custom HAL:              NO

  NVIDIA CUDA
    Use CUFFT:                   YES
    Use CUBLAS:                  YES
    USE NVCUVID:                 NO
    NVIDIA GPU arch:             20 30 35 37 50 52 60 61
    NVIDIA PTX archs:
    Use fast math:               YES

  OpenCL:                        <Dynamic loading of OpenCL library>
    Include path:                D:/OpenCV/sources/3rdparty/include/opencl/1.2
    Use AMDFFT:                  NO
    Use AMDBLAS:                 NO

  Python 2:
    Interpreter:                 NO

  Python 3:
    Interpreter:                 C:/Users/Ramesh/Anaconda3/python.exe (ver 3.5.3)
    Libraries:                   C:/Users/Ramesh/Anaconda3/libs/python35.lib (ver 3.5.3)
    numpy:                       C:/Users/Ramesh/Anaconda3/lib/site-packages/numpy/core/include (ver 1.13.0)
    packages path:               C:/Users/Ramesh/Anaconda3/Lib/site-packages

  Python (for build):            C:/Users/Ramesh/Anaconda3/python.exe

  Java:
    ant:                         NO
    JNI:                         C:/Program Files/Java/jdk1.8.0_112/include C:/Program Files/Java/jdk1.8.0_112/include/win32 C:/Program Files/Java/jdk1.8.0_112/include
    Java wrappers:               NO
    Java tests:                  NO

  Matlab:                        Matlab not found or implicitly disabled

  Documentation:
    Doxygen:                     D:/Program Files/doxygen/bin/doxygen.exe (ver 1.8.13)

  Tests and samples:
    Tests:                       NO
    Performance tests:           NO
    C/C++ Examples:              NO

  Install path:                  D:/OpenCV/build2/install

  cvconfig.h is in:              D:/OpenCV/build2
-----------------------------------------------------------------



但是我不能使用cv2.cuda包中的函数.当我运行help(cv2.cuda)



But I can't use functions in cv2.cuda package. When I run help(cv2.cuda)

Help on module cv2.cuda in cv2:

NAME
    cv2.cuda

DATA
    SURF_CUDA_ANGLE_ROW = 5
    SURF_CUDA_HESSIAN_ROW = 6
    SURF_CUDA_LAPLACIAN_ROW = 2
    SURF_CUDA_OCTAVE_ROW = 3
    SURF_CUDA_ROWS_COUNT = 7
    SURF_CUDA_SIZE_ROW = 4
    SURF_CUDA_X_ROW = 0
    SURF_CUDA_Y_ROW = 1

FILE
    (built-in)

结果表明模块cv2.cuda


我的问题是,


My Questions are,

  1. 有没有一种方法可以编译具有python3.5CUDA支持的opencv3.2?如问题所述,在opencv 2.4.7
  2. 中是不可能的
  3. 如果没有办法,我可以将c++函数与python绑定吗?我经历了
  1. Is there a way to compile opencv3.2 with CUDA support for python3.5..? As stated in this question, it was not possible in opencv 2.4.7
  2. If there is no way, can I bind c++ functions with python..? I went through opencv doc and I couldn't understand how to extend new modules to python. When I google it, I get some answers about writing wrappers (all answers are older than 4 years) but I couldn't understand how to bind data structures between 2 languages like c++ Mat with numpy.ndarray.

任何帮助将不胜感激!

推荐答案

通过遵循答案中所述,UMat

I was able to find a way to get cuda support for OpenCV python by following the tutorial in here (I did not test that). As far as I know GPUMat is not available. But UMat is available for python which can be used to access OpenCL.
As described in this answer, UMat is

一个统一的抽象cv :: UMat,它可以使用CPU或OpenCL代码实现相同的API,而无需显式调用OpenCL加速版本.如果系统中存在这些功能,则使用启用了OpenCL的GPU,否则将自动切换到CPU操作.

A unified abstraction cv::UMat that enables the same APIs to be implemented using CPU or OpenCL code, without a requirement to call OpenCL accelerated version explicitly. These functions use an OpenCL-enabled GPU if exists in the system, and automatically switch to CPU operation otherwise.

OpenCL部分此处所述,您只需将普通矩阵(在python np.ndarray s中)更改为UMat s(在python cv2.UMat中)即可获得OpenCL支持.

As described in OpenCL section here, you just have to change normal matrices (in python np.ndarrays) to UMats (in python cv2.UMat) to get the OpenCL support.

但是,当我需要cuda支持时,我要做的是,将该部分作为具有cuda支持的c++中的函数编写.我使该函数将cv::Mat图片作为参数并返回cv::Mat作为结果.

But what I do when I need cuda support is, I write that part as a function in c++ with cuda support. I make that function to take a cv::Mat image as the argument and return a cv::Mat as result.

然后按照此处所述为该函数编写python包装器.
.
那是一个有点旧的代码.但这在python 3.5python 2.7OpenCV 3.4

Then write a python wrapper for that function as described here.
That is a bit old code. But it worked for me on python 3.5 and python 2.7 with OpenCV 3.4

这篇关于Windows中具有CUDA的python的OpenCV 3.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆