如何检查opencv是否使用GPU?

Aji*_*ayl 6 python opencv gpu

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

Zab*_*azi 14

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

import cv2
count = cv2.cuda.getCudaEnabledDeviceCount()
print(count)
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

用opencv测试 4.2.0

  • 请不要发布文本屏幕的屏幕截图,而是发布文本本身(复制/粘贴等) (3认同)