How to check if opencv is using GPU or not?
10,935
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
Author by
Admin
Updated on July 29, 2022Comments
-
Admin almost 2 years
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 triedgetCudaEnabledDeviceCount()
this doesn't work and throws error too. -
lenik about 4 yearsplease, don't post screenshots of text screens, post the text itself (copy / paste etc)
-
Zabir Al Nazi about 4 yearsI have already posted the relevant code, the screenshot was just to demonstrate my opencv version as trying this on a lower version may not work. Should I remove it?
-
lenik about 4 yearsif you are able to copy / paste the contents instead of the screen shot -- the picture has to go =)