[英]How to check if opencv is using GPU or not?
I need to know if the current opencv installation is using GPU or not.我需要知道当前的 opencv 安装是否使用 GPU。 I tried
print(cv2.getBuildInformation())
but this is not what I'm looking for.我试过
print(cv2.getBuildInformation())
但这不是我想要的。 I also tried getCudaEnabledDeviceCount()
this doesn't work and throws error too.我也试过
getCudaEnabledDeviceCount()
这不起作用并且也会引发错误。
If you have installed cuda , there's a built-in function in opencv which you can use now.如果您已经安装了cuda ,那么您现在可以使用 opencv 中的内置function 。
import cv2
count = cv2.cuda.getCudaEnabledDeviceCount()
print(count)
count
returns the number of installed CUDA-enabled devices. count
返回已安装的支持 CUDA 的设备的数量。
You can use this function for handling all cases.您可以使用此 function 来处理所有情况。
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
Tested with opencv 4.2.0
用 opencv
4.2.0
测试
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.