Skip to content

Commit fbf2383

Browse files
committed
Merge pull request opencv#7787 from alalek:ocl_explicit_only
2 parents cb1d4e6 + 44d9d59 commit fbf2383

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

modules/core/include/opencv2/core/ocl.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,9 @@ CV_EXPORTS MatAllocator* getOpenCLAllocator();
739739
#ifdef __OPENCV_BUILD
740740
namespace internal {
741741

742+
CV_EXPORTS bool isOpenCLForced();
743+
#define OCL_FORCE_CHECK(condition) (cv::ocl::internal::isOpenCLForced() || (condition))
744+
742745
CV_EXPORTS bool isPerformanceCheckBypassed();
743746
#define OCL_PERFORMANCE_CHECK(condition) (cv::ocl::internal::isPerformanceCheckBypassed() || (condition))
744747

modules/core/src/ocl.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6073,6 +6073,18 @@ void* Image2D::ptr() const
60736073
return p ? p->handle : 0;
60746074
}
60756075

6076+
bool internal::isOpenCLForced()
6077+
{
6078+
static bool initialized = false;
6079+
static bool value = false;
6080+
if (!initialized)
6081+
{
6082+
value = getBoolParameter("OPENCV_OPENCL_FORCE", false);
6083+
initialized = true;
6084+
}
6085+
return value;
6086+
}
6087+
60766088
bool internal::isPerformanceCheckBypassed()
60776089
{
60786090
static bool initialized = false;

modules/features2d/src/orb.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -972,7 +972,7 @@ void ORB_Impl::detectAndCompute( InputArray _image, InputArray _mask,
972972
int halfPatchSize = patchSize / 2;
973973
int border = std::max(edgeThreshold, std::max(halfPatchSize, HARRIS_BLOCK_SIZE/2))+1;
974974

975-
bool useOCL = ocl::useOpenCL();
975+
bool useOCL = ocl::useOpenCL() && OCL_FORCE_CHECK(_image.isUMat() || _descriptors.isUMat());
976976

977977
Mat image = _image.getMat(), mask = _mask.getMat();
978978
if( image.type() != CV_8UC1 )

modules/objdetect/src/cascadedetect.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,8 +1290,8 @@ void CascadeClassifierImpl::detectMultiScaleNoGrouping( InputArray _image, std::
12901290

12911291
#ifdef HAVE_OPENCL
12921292
bool use_ocl = tryOpenCL && ocl::useOpenCL() &&
1293+
OCL_FORCE_CHECK(_image.isUMat()) &&
12931294
featureEvaluator->getLocalSize().area() > 0 &&
1294-
ocl::Device::getDefault().type() != ocl::Device::TYPE_CPU &&
12951295
(data.minNodesPerTree == data.maxNodesPerTree) &&
12961296
!isOldFormatCascade() &&
12971297
maskGenerator.empty() &&
@@ -1316,7 +1316,8 @@ void CascadeClassifierImpl::detectMultiScaleNoGrouping( InputArray _image, std::
13161316
// OpenCL code
13171317
CV_OCL_RUN(use_ocl, ocl_detectMultiScaleNoGrouping( scales, candidates ))
13181318

1319-
tryOpenCL = false;
1319+
if (use_ocl)
1320+
tryOpenCL = false;
13201321
#endif
13211322

13221323
// CPU code

0 commit comments

Comments
 (0)