I need to know if the current opencv installation is using GPU or not. I tried print(cv2.getBuildInformation())
but this is not what I'm looking for. I also tried getCudaEnabledDeviceCount()
this doesn't work and throws error too.
If you have installed cuda , there's a built-in function in opencv which you can use now.
import cv2
count = cv2.cuda.getCudaEnabledDeviceCount()
print(count)
count
returns the number of installed CUDA-enabled devices.
You can use this function for handling all cases.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.