Python and gpu OpenCV functions

13,807

Solution 1

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

That means that you must write wrappers yourself.

Solution 2

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:

Share:
13,807
Katsu
Author by

Katsu

Updated on June 15, 2022

Comments

  • Katsu
    Katsu almost 2 years

    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
    Katsu over 10 years
    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)
  • karlphillip
    karlphillip over 10 years
    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.
  • fbence
    fbence over 7 years
    Since it's been 3 years since the answer and OpenCV 3 is out, is this still the case?
  • Farhan
    Farhan almost 6 years
    @fbence Yes, unfortunately this is still the case.
  • Farhan
    Farhan almost 6 years
  • fbence
    fbence almost 6 years
    @Farhan there seems to be a contradictory answer alreasy
  • Farhan
    Farhan almost 6 years
    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
    Farhan almost 6 years
    @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).
  • Neeraj Gulia
    Neeraj Gulia over 5 years