我需要知道当前的 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/