【发布时间】:2020-08-12 23:45:13
【问题描述】:
我需要知道当前的 opencv 安装是否使用 GPU。我试过print(cv2.getBuildInformation()) 但这不是我想要的。我也试过getCudaEnabledDeviceCount()这不起作用,也会抛出错误。
【问题讨论】:
我需要知道当前的 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
【讨论】: