Merge pull request #18386 from JulienMaille:patch-1
authorJulien <182520+JulienMaille@users.noreply.github.com>
Wed, 23 Sep 2020 09:15:02 +0000 (11:15 +0200)
committerGitHub <noreply@github.com>
Wed, 23 Sep 2020 09:15:02 +0000 (09:15 +0000)
* Make sure there is a cuda device before getting it

* Update init.hpp

modules/dnn/src/cuda4dnn/init.hpp

index b548f09..e9d9973 100644 (file)
@@ -57,6 +57,9 @@ namespace cv { namespace dnn { namespace cuda4dnn {
 
     bool isDeviceCompatible()
     {
+        if (getDeviceCount() <= 0)
+            return false;
+
         int device_id = getDevice();
         if (device_id < 0)
             return false;
@@ -77,6 +80,9 @@ namespace cv { namespace dnn { namespace cuda4dnn {
 
     bool doesDeviceSupportFP16()
     {
+        if (getDeviceCount() <= 0)
+            return false;
+
         int device_id = getDevice();
         if (device_id < 0)
             return false;