8

I want to know if it is possible to use opencv gpu functions like those from here? Or I have to wrap it into python class.

Katsu
  • 1,868
  • 4
  • 19
  • 28
  • There is an approach discussed: https://stackoverflow.com/questions/42125084/accessing-opencv-cuda-functions-from-python-no-pycuda/52436378#52436378 – Neeraj Gulia Jan 31 '19 at 05:54
  • Possible duplicate of [Accessing OpenCV CUDA Functions from Python (No PyCUDA)](https://stackoverflow.com/questions/42125084/accessing-opencv-cuda-functions-from-python-no-pycuda) – c-x-berger Jun 19 '19 at 16:56

2 Answers2

6

Right now OpenCV 2.4.7 doesn't support the GPU module on OpenCV-Python.

That means that you must write wrappers yourself.

Community
  • 1
  • 1
karlphillip
  • 92,053
  • 36
  • 243
  • 426
  • Ok thank's, I did it, but in fact it's useless to wrap it because it's faster on CPU (allocation on GPU take more time) – Katsu Nov 25 '13 at 16:17
  • The performance of GPU processing depends on a few factors: how fast the GPU is, how big the dimensions of the image are, and finally, the arithmetic intensity of the algorithm. In some cases the CPU will really be faster! But that usually happens with small images or with algorithms with low arithmetic intensity. – karlphillip Nov 25 '13 at 16:42
  • 5
    Since it's been 3 years since the answer and OpenCV 3 is out, is this still the case? – fbence Oct 21 '16 at 20:29
  • @fbence Yes, unfortunately this is still the case. – Farhan Jul 07 '18 at 00:38
  • @Farhan there seems to be a contradictory answer alreasy – fbence Jul 07 '18 at 12:49
  • @fbence The answer is incorrect. See my comments on the answer. While it is possible to *compile* OpenCV with both Python and CUDA support, you cannot *use* the CUDA modules in Python because OpenCV doesn't have external bindings (Java or Python) to its CUDA modules (most likely because OpenCV uses custom data structures like `GpuMat` which have no counterparts in those languages). This means that if you want to write CUDA accelerated OpenCV code, you must write it in C++ (and then wrap in Python if desired). – Farhan Jul 09 '18 at 21:38
1

To answer the question in the comment made by fbence in the accepted answer, this is now possible with OpenCV 3 and Python 2.7+ or Python 3+. However, the OpenCV 3 GPU module must be compiled from source.

Assuming you are working on a Linux system you can follow these guides:

sparkitny
  • 1,503
  • 4
  • 18
  • 23
  • 2
    This is incorrect! [OpenCV does not have python bindings for CUDA enabled classes](https://stackoverflow.com/questions/42125084/accessing-opencv-cuda-functions-from-python-no-pycuda). – Farhan Jul 07 '18 at 00:52
  • 3
    In fact, you can see in the guide for Python 3 that the author compiles OpenCV with the flag "-D WITH_CUDA=OFF"! This means the author isn't even compiling OpenCV with CUDA support! – Farhan Jul 09 '18 at 21:33
  • 1
    Follow this answer: https://stackoverflow.com/questions/42125084/accessing-opencv-cuda-functions-from-python-no-pycuda/52436378#52436378 – Neeraj Gulia Jan 31 '19 at 05:53