diff --git a/modules/dnn/src/dnn.cpp b/modules/dnn/src/dnn.cpp index 194648c6ea..15755f73e9 100644 --- a/modules/dnn/src/dnn.cpp +++ b/modules/dnn/src/dnn.cpp @@ -53,6 +53,7 @@ #include #include +#include namespace cv { namespace dnn { @@ -846,6 +847,13 @@ struct Net::Impl if (!netWasAllocated || this->blobsToKeep != blobsToKeep_) { +#ifndef HAVE_OPENCL + if (preferableBackend == DNN_BACKEND_DEFAULT && preferableTarget == DNN_TARGET_OPENCL) + { + CV_LOG_WARNING(NULL, "DNN: OpenCL target is not available in this OpenCV build, switching to CPU.") + preferableTarget = DNN_TARGET_CPU; + } +#endif clear(); allocateLayers(blobsToKeep_);