OpenCV 3.2 CUDA支持python [英] OpenCV 3.2 CUDA support python
问题描述
我刚刚按照 http://www.pyimagesearch.com/2016/07/11/compiling-opencv-with-cuda-support/ 我只是想知道如何在运行时检查我的OpenCV是否使用CUDA和GPU支持(我使用python2.7)
I've just installed OpenCV 3.2 compiling with CUDA support following instruction in http://www.pyimagesearch.com/2016/07/11/compiling-opencv-with-cuda-support/ I just wonder how to check whether my OpenCV is using CUDA and GPU support when running (I use python2.7)
推荐答案
As you can see in the link you gave, you can always check whether you have installed CUDA
correctly by typing this on python
console.
print(cv2.getBuildInformation())
如果您具有CUDA支持,则会在打印的文本中看到Use CUDA: YES (version)
.
If you have CUDA support, you will be seen that Use CUDA: YES (version)
in the printed text.
然后您可以在以下命令中使用 opencv cuda 命令 cv2.cuda
模块.
Then you can use opencv cuda commands in cv2.cuda
module.
但是正如该教程中所述,CUDA
目前在python中不提供支持. (由于这些教程位于OpenCV python
上,因此您是否会为python
增加CUDA
支持会感到困惑.但是 不会. ))
But as said in that tutorial CUDA
support is not there at present in python. (As these tutorials are on OpenCV python
you will get confused whether this will add CUDA
support for python
. But it will not..)
此外,在支持GPU的CUDA环境中,我们可以对OpenCV进行许多编译时优化,以使其能够利用GPU进行更快的计算(但主要用于C ++应用程序,而对于C ++应用程序则没有那么多Python,至少目前是这样.
Furthermore, in a GPU-enabled CUDA environment, there are a number of compile-time optimizations we can make to OpenCV, allowing it to take advantage of the GPU for faster computation (but mainly for C++ applications, not so much for Python, at least at the present time).
但是,如此答案中所述,您可以获得python上的OpenCL
支持.如此文档
But as described in this answer, you can get OpenCL
support on python. As in this document,
开放计算语言(OpenCL)是一种开放标准,用于编写跨异构平台(包括CPU,GPU,DSP等)运行的代码.
Open Computing Language (OpenCL) is an open standard for writing code that runs across heterogeneous platforms including CPUs, GPUs, DSPs and etc.
您可以做的另一件事是,您可以为OpenCV C++
中的每个GPU
方法编写python
包装器,然后通过python
调用这些方法.我不建议这样做,因为这将始终在GPU
内存和RAM
之间复制图像和其他数据,从而导致性能下降.有时,这将比单独使用CPU
花费更多的时间.
Another thing that you can do is, you can write python
wrappers for each GPU
methods in OpenCV C++
and call those methods via python
. I will not recommend that because this will always copy images and other data between GPU
memory and RAM
resulting bad performance. Sometimes this will take more time than CPU
alone.
您可以做的另一件事是使用C++
中的GPU
编写所需完成的整个函数,并为该函数编写一个python
包装器.这比以前的方法要好得多,但是您需要了解C++
.
Another thing that you can do is writing the whole function you need to do using GPU
in C++
and write a python
wrapper for that function. This is much more better than the previous method but you will need to know C++
.
可能会有更好的方法.
这篇关于OpenCV 3.2 CUDA支持python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!