Skip to content

Commit a9ebc61

Browse files
committed
dnn(workaround): switch to CPU target if compiled without OpenCL
1 parent 1b83bc4 commit a9ebc61

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

modules/dnn/src/dnn.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include <opencv2/imgproc.hpp>
5454

5555
#include <opencv2/core/utils/configuration.private.hpp>
56+
#include <opencv2/core/utils/logger.hpp>
5657

5758
namespace cv {
5859
namespace dnn {
@@ -846,6 +847,13 @@ struct Net::Impl
846847

847848
if (!netWasAllocated || this->blobsToKeep != blobsToKeep_)
848849
{
850+
#ifndef HAVE_OPENCL
851+
if (preferableBackend == DNN_BACKEND_DEFAULT && preferableTarget == DNN_TARGET_OPENCL)
852+
{
853+
CV_LOG_WARNING(NULL, "DNN: OpenCL target is not available in this OpenCV build, switching to CPU.")
854+
preferableTarget = DNN_TARGET_CPU;
855+
}
856+
#endif
849857
clear();
850858

851859
allocateLayers(blobsToKeep_);

0 commit comments

Comments
 (0)