Ask Your Question
0

Can't find GpuMAT() functions in v4.2.0-dev compiled with python & CUDA

asked 2019-12-27 13:01:56 -0600

AstroBen gravatar image

updated 2019-12-27 14:06:41 -0600

I have "successfully" compiled OpenCV v4.2.0-dev with python bindings and CUDA support on my Windows 10 machine following the many directions available online. I say successfully because compilation didn't throw errors. However, when I try to run a cv2.cuda command, I get an error such as:

>>>q=cv2.cuda.resize(base,dsize=(100,100))

---------------------------------------------------------------------------
error                                     Traceback (most recent call last) <ipython-input-10-f4bd798fbe4a> in <module>
----> 1 q=cv2.cuda.resize(base,dsize=(100,100))

error: OpenCV(4.2.0-dev) C:\Users\M43259\Documents\python\opencv\modules\core\src\matrix_wrap.cpp:359: error: (-213:The function/feature is not implemented) getGpuMat is available only for cuda::GpuMat and cuda::HostMem in function 'cv::_InputArray::getGpuMat'

It turns out there is no python call available that has anything with GpuMAT in it. For example:

>>>cv2.cuda_GpuMAT()

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last) <ipython-input-11-c14055330a2d> in <module>
----> 1 cv2.cuda_GpuMAT()

AttributeError: module 'cv2' has no attribute 'cuda_GpuMAT'

I'm stumped. I can provide loads of files and details if anyone wants.

EDIT 1 -------

While I'm looking for relevant cmake outputs, here is the output from cv2.getBuildInformation()

General configuration for OpenCV 4.2.0-dev =====================================
  Version control:               4.2.0-1-g89d3f95a8e

  Extra modules:
    Location (extra):            C:/Users/M43259/Documents/python/opencv_contrib/modules
    Version control (extra):     4.2.0

  Platform:
    Timestamp:                   2019-12-26T17:26:27Z
    Host:                        Windows 10.0.16299 AMD64
    CMake:                       3.16.2
    CMake generator:             Visual Studio 15 2017
    CMake build tool:            C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/MSBuild/15.0/Bin/MSBuild.exe
    MSVC:                        1914

  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 (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 (29 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
      AVX512_SKX (6 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++ Compiler:                C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.14.26428/bin/Hostx86/x64/cl.exe  (ver 19.14.26430.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 /MP8   /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 /MP8   /MDd /Zi /Ob0 /Od /RTC1 
    C Compiler:                  C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/VC/Tools/MSVC/14.14.26428/bin/Hostx86/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       /MP8    /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       /MP8  /MDd /Zi /Ob0 /Od /RTC1 
    Linker ...
(more)
edit retag flag offensive close merge delete

Comments

please append the cmake output to your question

(it seems, it did not properly pick up cuda components)

berak gravatar imageberak ( 2019-12-27 13:43:59 -0600 )edit

I quit the cmake.exe and VS2017 programs yesterday so I don't have those outputs on a screen. Do you have thoughts of what files on disk might be helpful instead? I did edit the question to include the getBuildInformation if that is helpful to start with?

AstroBen gravatar imageAstroBen ( 2019-12-27 14:07:55 -0600 )edit

That's strange, from your build info CUDA was picked up. Your GpuMat error is consistent with not having built with CUDA however I would expect your resize error to resemble the below

AttributeError: module 'cv2.cuda' has no attribute 'resize'

How did you install the python binary (cv2.cp37-win_amd64.pyd)? Did you manually copy it into the site-packages directory? Are other functions from cv2 working? Do you also have opencv installed through conda? If you didn't build with -DOPENCV_SKIP_PYTHON_LOADER=ON it may be worth deleting the site-packages/cv2 directory and manually copying cv2.cp37-win_amd64.pyd directly into site-packages. I guess

where opencv_world420.dll

shows the path to the dll built with CUDA and not one which you built previously without?

cudawarped gravatar imagecudawarped ( 2019-12-28 02:18:40 -0600 )edit

Does this help? Unfortunately, don't use key.

q=cv2.cuda.resize(base,dsize=(100,100))

to:

q=cv2.cuda.resize(base, (100,100))

or: dsize = 100, 100

q=cv2.cuda.resize(base,dsize)
supra56 gravatar imagesupra56 ( 2019-12-28 09:57:11 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2019-12-28 12:57:20 -0600

updated 2019-12-28 13:11:31 -0600

Nice spot by @supra56. CUDA looks to be installed properly, you are just passing the wrong arguments and not using autocomplete for function names.

GpuMat should be working fine, you just have a typo (always best to use autocomplete), it should be

cv2.cuda_GpuMat()

not

cv2.cuda_GpuMAT()

I think the second problem is that you are passing a numpy array instead of a GpuMat to resize. Some cuda functions may accept numpy arrays but I would advise against it and always pass GpuMat unless the function explicitly requires a numpy array. All that said all the below should work

cuMat = cv2.cuda_GpuMat(npMat)
q = cv2.cuda.resize(cuMat,dsize=(100,100))

or

q=cv2.cuda.resize(cv2.cuda_GpuMat(npMat),dsize=(100,100))

or

q = cv2.cuda_GpuMat((100,100),cuMat.type())
cv2.cuda.resize(cuMat,(100,100),q)

I would suggest the last one because it avoids allocating the return matrix on each invocation, so it will be much much faster, which you can verify by comparing

%timeit cv2.cuda.resize(cuMat,(100,100))
%timeit cv2.cuda.resize(cuMat,(100,100),q)
edit flag offensive delete link more

Comments

@cudawarped. THANKS!. I just dowloaded OpenCV 4.2.0 Unfortunately, haven't attempted yet. I will test it.

supra56 gravatar imagesupra56 ( 2019-12-28 16:02:36 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-12-27 13:01:56 -0600

Seen: 3,197 times

Last updated: Dec 28 '19