diff --git a/modules/dnn/src/layers/convolution_layer.cpp b/modules/dnn/src/layers/convolution_layer.cpp index cf2ab8c8e..13bc1911b 100644 --- a/modules/dnn/src/layers/convolution_layer.cpp +++ b/modules/dnn/src/layers/convolution_layer.cpp @@ -153,6 +153,7 @@ namespace dnn return; } +#ifdef HAVE_OPENCL if (useOpenCL && ocl::useOpenCL() && inpBlob.type() == CV_32F && !is1x1()) { std::vector ranges(4, Range::all()); @@ -165,6 +166,7 @@ namespace dnn dst.copyTo(colMat); return; } +#endif // HAVE_OPENCL if (inpBlob.type() == CV_32F) im2col_cpu((float *)srcPtr, inpGroupCn, inpH, inpW, kerH, kerW, padH, padW, strideH, strideW, (float *)colMat.ptr()); diff --git a/modules/dnn/src/layers/im2col.cpp b/modules/dnn/src/layers/im2col.cpp index a8ef7e005..a4f9e7675 100644 --- a/modules/dnn/src/layers/im2col.cpp +++ b/modules/dnn/src/layers/im2col.cpp @@ -49,6 +49,7 @@ namespace cv namespace dnn { +#ifdef HAVE_OPENCL void im2col_ocl(UMat &img, int channels, int height, int width, int kernel_h, int kernel_w, @@ -78,6 +79,7 @@ void im2col_ocl(UMat &img, CV_Assert(im2col_ker.run(1, &globalSize, &localSize, true)); } +#endif // HAVE_OPENCL } } diff --git a/modules/dnn/src/layers/im2col.hpp b/modules/dnn/src/layers/im2col.hpp index dc1432e03..d3353e332 100644 --- a/modules/dnn/src/layers/im2col.hpp +++ b/modules/dnn/src/layers/im2col.hpp @@ -111,12 +111,14 @@ void col2im_cpu(const Dtype* data_col, } } +#ifdef HAVE_OPENCL void im2col_ocl(UMat &img, int channels, int height, int width, int kernel_h, int kernel_w, int pad_h, int pad_w, int stride_h, int stride_w, UMat &col); +#endif } } diff --git a/modules/tracking/src/tldDetector.cpp b/modules/tracking/src/tldDetector.cpp index a927b69e1..7136e70fa 100644 --- a/modules/tracking/src/tldDetector.cpp +++ b/modules/tracking/src/tldDetector.cpp @@ -83,6 +83,7 @@ namespace cv return splus / (sminus + splus); } +#ifdef HAVE_OPENCL double TLDDetector::ocl_Sr(const Mat_& patch) { double splus = 0.0, sminus = 0.0; @@ -185,6 +186,7 @@ namespace cv resultSc[id] = spc / (smc + spc); } } +#endif // Calculate Conservative similarity of the patch (NN-Model) double TLDDetector::Sc(const Mat_& patch) @@ -212,6 +214,7 @@ namespace cv return splus / (sminus + splus); } +#ifdef HAVE_OPENCL double TLDDetector::ocl_Sc(const Mat_& patch) { double splus = 0.0, sminus = 0.0; @@ -256,6 +259,7 @@ namespace cv return 0.0; return splus / (sminus + splus); } +#endif // HAVE_OPENCL // Generate Search Windows for detector from aspect ratio of initial BBs void TLDDetector::generateScanGrid(int rows, int cols, Size initBox, std::vector& res, bool withScaling) @@ -393,6 +397,7 @@ namespace cv } } +#ifdef HAVE_OPENCL bool TLDDetector::ocl_detect(const Mat& img, const Mat& imgBlurred, Rect2d& res, std::vector& patches, Size initSize) { patches.clear(); @@ -507,6 +512,7 @@ namespace cv res = maxScRect; return true; } +#endif // HAVE_OPENCL // Computes the variance of subimage given by box, with the help of two integral // images intImgP and intImgP2 (sum of squares), which should be also provided. diff --git a/modules/tracking/src/tldDetector.hpp b/modules/tracking/src/tldDetector.hpp index 7f5a3f9e5..742125696 100644 --- a/modules/tracking/src/tldDetector.hpp +++ b/modules/tracking/src/tldDetector.hpp @@ -76,10 +76,12 @@ namespace cv double ensembleClassifierNum(const uchar* data); void prepareClassifiers(int rowstep); double Sr(const Mat_& patch); - double ocl_Sr(const Mat_& patch); double Sc(const Mat_& patch); +#ifdef HAVE_OPENCL + double ocl_Sr(const Mat_& patch); double ocl_Sc(const Mat_& patch); void ocl_batchSrSc(const Mat_& patches, double *resultSr, double *resultSc, int numOfPatches); +#endif std::vector classifiers; Mat *posExp, *negExp; diff --git a/modules/tracking/src/tldModel.cpp b/modules/tracking/src/tldModel.cpp index 9415c2a99..03d922e50 100644 --- a/modules/tracking/src/tldModel.cpp +++ b/modules/tracking/src/tldModel.cpp @@ -219,6 +219,7 @@ namespace cv } } +#ifdef HAVE_OPENCL void TrackerTLDModel::ocl_integrateAdditional(const std::vector >& eForModel, const std::vector >& eForEnsemble, bool isPositive) { int positiveIntoModel = 0, negativeIntoModel = 0, positiveIntoEnsemble = 0, negativeIntoEnsemble = 0; @@ -271,6 +272,7 @@ namespace cv } } } +#endif // HAVE_OPENCL //Push the patch to the model void TrackerTLDModel::pushIntoModel(const Mat_& example, bool positive) diff --git a/modules/tracking/src/tldModel.hpp b/modules/tracking/src/tldModel.hpp index be9141a54..ba7c9269f 100644 --- a/modules/tracking/src/tldModel.hpp +++ b/modules/tracking/src/tldModel.hpp @@ -58,7 +58,9 @@ namespace cv void setBoudingBox(Rect2d boundingBox){ boundingBox_ = boundingBox; } void integrateRelabeled(Mat& img, Mat& imgBlurred, const std::vector& patches); void integrateAdditional(const std::vector >& eForModel, const std::vector >& eForEnsemble, bool isPositive); +#ifdef HAVE_OPENCL void ocl_integrateAdditional(const std::vector >& eForModel, const std::vector >& eForEnsemble, bool isPositive); +#endif Size getMinSize(){ return minSize_; } void printme(FILE* port = stdout); Ptr detector; diff --git a/modules/tracking/src/tldTracker.cpp b/modules/tracking/src/tldTracker.cpp index a1334a91c..51d994efc 100644 --- a/modules/tracking/src/tldTracker.cpp +++ b/modules/tracking/src/tldTracker.cpp @@ -129,9 +129,11 @@ bool TrackerTLDImpl::updateImpl(const Mat& image, Rect2d& boundingBox) if (i == 1) { +#ifdef HAVE_OPENCL if (ocl::haveOpenCL()) DETECT_FLG = tldModel->detector->ocl_detect(imageForDetector, image_blurred, tmpCandid, detectorResults, tldModel->getMinSize()); else +#endif DETECT_FLG = tldModel->detector->detect(imageForDetector, image_blurred, tmpCandid, detectorResults, tldModel->getMinSize()); } if( ( (i == 0) && !data->failedLastTime && trackerProxy->update(image, tmpCandid) ) || ( DETECT_FLG)) @@ -199,17 +201,21 @@ bool TrackerTLDImpl::updateImpl(const Mat& image, Rect2d& boundingBox) } tldModel->integrateRelabeled(imageForDetector, image_blurred, detectorResults); pExpert.additionalExamples(examplesForModel, examplesForEnsemble); - if (ocl::haveOpenCL()) - tldModel->ocl_integrateAdditional(examplesForModel, examplesForEnsemble, true); - else - tldModel->integrateAdditional(examplesForModel, examplesForEnsemble, true); +#ifdef HAVE_OPENCL + if (ocl::haveOpenCL()) + tldModel->ocl_integrateAdditional(examplesForModel, examplesForEnsemble, true); + else +#endif + tldModel->integrateAdditional(examplesForModel, examplesForEnsemble, true); examplesForModel.clear(); examplesForEnsemble.clear(); nExpert.additionalExamples(examplesForModel, examplesForEnsemble); - if (ocl::haveOpenCL()) - tldModel->ocl_integrateAdditional(examplesForModel, examplesForEnsemble, false); - else - tldModel->integrateAdditional(examplesForModel, examplesForEnsemble, false); +#ifdef HAVE_OPENCL + if (ocl::haveOpenCL()) + tldModel->ocl_integrateAdditional(examplesForModel, examplesForEnsemble, false); + else +#endif + tldModel->integrateAdditional(examplesForModel, examplesForEnsemble, false); } else { diff --git a/modules/xfeatures2d/src/surf.cpp b/modules/xfeatures2d/src/surf.cpp index 673817e73..af5ceaf60 100644 --- a/modules/xfeatures2d/src/surf.cpp +++ b/modules/xfeatures2d/src/surf.cpp @@ -892,6 +892,7 @@ void SURF_Impl::detectAndCompute(InputArray _img, InputArray _mask, CV_Assert(!_img.empty() && CV_MAT_DEPTH(imgtype) == CV_8U && (imgcn == 1 || imgcn == 3 || imgcn == 4)); CV_Assert(_descriptors.needed() || !useProvidedKeypoints); +#ifdef HAVE_OPENCL if( ocl::useOpenCL() ) { SURF_OCL ocl_surf; @@ -918,6 +919,7 @@ void SURF_Impl::detectAndCompute(InputArray _img, InputArray _mask, return; } } +#endif // HAVE_OPENCL Mat img = _img.getMat(), mask = _mask.getMat(), mask1, sum, msum; diff --git a/modules/xfeatures2d/src/surf.hpp b/modules/xfeatures2d/src/surf.hpp index 2c4e271f2..cf3fda16b 100644 --- a/modules/xfeatures2d/src/surf.hpp +++ b/modules/xfeatures2d/src/surf.hpp @@ -64,6 +64,7 @@ public: bool upright; }; +#ifdef HAVE_OPENCL class SURF_OCL { public: @@ -145,6 +146,7 @@ protected: int status; }; +#endif // HAVE_OPENCL /* template void copyVectorToUMat(const std::vector<_Tp>& v, UMat& um) diff --git a/modules/xfeatures2d/src/surf.ocl.cpp b/modules/xfeatures2d/src/surf.ocl.cpp index 49f4d073a..bf1c97c29 100644 --- a/modules/xfeatures2d/src/surf.ocl.cpp +++ b/modules/xfeatures2d/src/surf.ocl.cpp @@ -43,6 +43,9 @@ // //M*/ #include "precomp.hpp" + +#ifdef HAVE_OPENCL + #include "surf.hpp" #include @@ -461,3 +464,4 @@ bool SURF_OCL::calcOrientation(UMat &keypoints) } } +#endif // HAVE_OPENCL