python - 如何检查opencv是否使用GPU?

标签 python opencv gpu

我需要知道当前的 opencv 安装是否使用 GPU。我试过 print(cv2.getBuildInformation()) 但这不是我要找的。我也试过 getCudaEnabledDeviceCount() 这不起作用并且也抛出错误。

最佳答案

如果您已经安装了 cuda ,那么您现在可以使用 opencv 中的一个内置函数。

import cv2
count = cv2.cuda.getCudaEnabledDeviceCount()
print(count)
count 返回已安装的支持 CUDA 的设备的数量。
您可以使用此功能处理所有情况。
def is_cuda_cv(): # 1 == using cuda, 0 = not using cuda
    try:
        count = cv2.cuda.getCudaEnabledDeviceCount()
        if count > 0:
            return 1
        else:
            return 0
    except:
        return 0
用 opencv 4.2.0 测试

关于python - 如何检查opencv是否使用GPU?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61492452/

相关文章:

image - OpenCV 比较图像

python - 如何在使用python检测边缘后将图像裁剪成碎片

gpu - Spacy + GPU 给出错误 : GPU is not accessible. 库是否安装正确?

azure - 如何在 Windows Azure VM 中启用 GPU

for-loop - 在 for 循环中重复调用内核的 CUDA 程序的性能受到影响

Python MySQLdb 在 Python 命令行上运行,但不能在 Django Views.py 上运行

opencv - 计算两个坐标系中给定点之间的变换

python - 在 Tkinter 中加载 TrueType 字体文件而不将其安装在字体文件夹中

python - 从集合中删除满足谓词的所有元素

python - 如何理解Class中的 `self.fields`?