Skip to content

Commit ac8dd36

Browse files
committed
ocl: fix "off" mode
1 parent 22f5843 commit ac8dd36

File tree

11 files changed

+41
-9
lines changed

11 files changed

+41
-9
lines changed

modules/dnn/src/layers/convolution_layer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ namespace dnn
153153
return;
154154
}
155155

156+
#ifdef HAVE_OPENCL
156157
if (useOpenCL && ocl::useOpenCL() && inpBlob.type() == CV_32F && !is1x1())
157158
{
158159
std::vector<Range> ranges(4, Range::all());
@@ -165,6 +166,7 @@ namespace dnn
165166
dst.copyTo(colMat);
166167
return;
167168
}
169+
#endif // HAVE_OPENCL
168170

169171
if (inpBlob.type() == CV_32F)
170172
im2col_cpu((float *)srcPtr, inpGroupCn, inpH, inpW, kerH, kerW, padH, padW, strideH, strideW, (float *)colMat.ptr());

modules/dnn/src/layers/im2col.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ namespace cv
4949
namespace dnn
5050
{
5151

52+
#ifdef HAVE_OPENCL
5253
void im2col_ocl(UMat &img,
5354
int channels, int height, int width,
5455
int kernel_h, int kernel_w,
@@ -78,6 +79,7 @@ void im2col_ocl(UMat &img,
7879

7980
CV_Assert(im2col_ker.run(1, &globalSize, &localSize, true));
8081
}
82+
#endif // HAVE_OPENCL
8183

8284
}
8385
}

modules/dnn/src/layers/im2col.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,14 @@ void col2im_cpu(const Dtype* data_col,
111111
}
112112
}
113113

114+
#ifdef HAVE_OPENCL
114115
void im2col_ocl(UMat &img,
115116
int channels, int height, int width,
116117
int kernel_h, int kernel_w,
117118
int pad_h, int pad_w,
118119
int stride_h, int stride_w,
119120
UMat &col);
121+
#endif
120122

121123
}
122124
}

modules/tracking/src/tldDetector.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ namespace cv
104104
return splus / (sminus + splus);
105105
}
106106

107+
#ifdef HAVE_OPENCL
107108
double TLDDetector::ocl_Sr(const Mat_<uchar>& patch)
108109
{
109110
//int64 e1, e2, e3, e4;
@@ -283,6 +284,7 @@ namespace cv
283284
//t = (e2 - e1) / getTickFrequency()*1000.0;
284285
//printf("Sr GPU: %f\n\n", t);
285286
}
287+
#endif
286288

287289
// Calculate Conservative similarity of the patch (NN-Model)
288290
double TLDDetector::Sc(const Mat_<uchar>& patch)
@@ -337,6 +339,7 @@ namespace cv
337339
return splus / (sminus + splus);
338340
}
339341

342+
#ifdef HAVE_OPENCL
340343
double TLDDetector::ocl_Sc(const Mat_<uchar>& patch)
341344
{
342345
//int64 e1, e2, e3, e4;
@@ -415,6 +418,7 @@ namespace cv
415418
return 0.0;
416419
return splus / (sminus + splus);
417420
}
421+
#endif // HAVE_OPENCL
418422

419423
// Generate Search Windows for detector from aspect ratio of initial BBs
420424
void TLDDetector::generateScanGrid(int rows, int cols, Size initBox, std::vector<Rect2d>& res, bool withScaling)
@@ -565,6 +569,7 @@ namespace cv
565569
return true;
566570
}
567571

572+
#ifdef HAVE_OPENCL
568573
bool TLDDetector::ocl_detect(const Mat& img, const Mat& imgBlurred, Rect2d& res, std::vector<LabeledPatch>& patches, Size initSize)
569574
{
570575
patches.clear();
@@ -696,6 +701,7 @@ namespace cv
696701
res = maxScRect;
697702
return true;
698703
}
704+
#endif // HAVE_OPENCL
699705

700706
// Computes the variance of subimage given by box, with the help of two integral
701707
// images intImgP and intImgP2 (sum of squares), which should be also provided.

modules/tracking/src/tldDetector.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,12 @@ namespace cv
7474
inline double ensembleClassifierNum(const uchar* data);
7575
inline void prepareClassifiers(int rowstep);
7676
double Sr(const Mat_<uchar>& patch);
77-
double ocl_Sr(const Mat_<uchar>& patch);
7877
double Sc(const Mat_<uchar>& patch);
78+
#ifdef HAVE_OPENCL
79+
double ocl_Sr(const Mat_<uchar>& patch);
7980
double ocl_Sc(const Mat_<uchar>& patch);
8081
void ocl_batchSrSc(const Mat_<uchar>& patches, double *resultSr, double *resultSc, int numOfPatches);
82+
#endif
8183

8284
std::vector<TLDEnsembleClassifier> classifiers;
8385
Mat *posExp, *negExp;

modules/tracking/src/tldModel.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ namespace cv
246246
dfprintf((stdout, "\n"));*/
247247
}
248248

249+
#ifdef HAVE_OPENCL
249250
void TrackerTLDModel::ocl_integrateAdditional(const std::vector<Mat_<uchar> >& eForModel, const std::vector<Mat_<uchar> >& eForEnsemble, bool isPositive)
250251
{
251252
int positiveIntoModel = 0, negativeIntoModel = 0, positiveIntoEnsemble = 0, negativeIntoEnsemble = 0;
@@ -315,6 +316,7 @@ namespace cv
315316
dfprintf((stdout, "positiveIntoEnsemble = %d ", positiveIntoEnsemble));
316317
dfprintf((stdout, "\n"));*/
317318
}
319+
#endif // HAVE_OPENCL
318320

319321
//Push the patch to the model
320322
void TrackerTLDModel::pushIntoModel(const Mat_<uchar>& example, bool positive)

modules/tracking/src/tldModel.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ namespace cv
5858
void setBoudingBox(Rect2d boundingBox){ boundingBox_ = boundingBox; }
5959
void integrateRelabeled(Mat& img, Mat& imgBlurred, const std::vector<TLDDetector::LabeledPatch>& patches);
6060
void integrateAdditional(const std::vector<Mat_<uchar> >& eForModel, const std::vector<Mat_<uchar> >& eForEnsemble, bool isPositive);
61+
#ifdef HAVE_OPENCL
6162
void ocl_integrateAdditional(const std::vector<Mat_<uchar> >& eForModel, const std::vector<Mat_<uchar> >& eForEnsemble, bool isPositive);
63+
#endif
6264
Size getMinSize(){ return minSize_; }
6365
void printme(FILE* port = stdout);
6466
Ptr<TLDDetector> detector;

modules/tracking/src/tldTracker.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,11 @@ bool TrackerTLDImpl::updateImpl(const Mat& image, Rect2d& boundingBox)
123123

124124
if (i == 1)
125125
{
126+
#ifdef HAVE_OPENCL
126127
if (ocl::haveOpenCL())
127128
DETECT_FLG = tldModel->detector->ocl_detect(imageForDetector, image_blurred, tmpCandid, detectorResults, tldModel->getMinSize());
128129
else
130+
#endif
129131
DETECT_FLG = tldModel->detector->detect(imageForDetector, image_blurred, tmpCandid, detectorResults, tldModel->getMinSize());
130132
}
131133

@@ -211,17 +213,21 @@ bool TrackerTLDImpl::updateImpl(const Mat& image, Rect2d& boundingBox)
211213
tldModel->integrateRelabeled(imageForDetector, image_blurred, detectorResults);
212214
//dprintf(("%d relabeled by nExpert\n", negRelabeled));
213215
pExpert.additionalExamples(examplesForModel, examplesForEnsemble);
214-
if (ocl::haveOpenCL())
215-
tldModel->ocl_integrateAdditional(examplesForModel, examplesForEnsemble, true);
216-
else
217-
tldModel->integrateAdditional(examplesForModel, examplesForEnsemble, true);
216+
#ifdef HAVE_OPENCL
217+
if (ocl::haveOpenCL())
218+
tldModel->ocl_integrateAdditional(examplesForModel, examplesForEnsemble, true);
219+
else
220+
#endif
221+
tldModel->integrateAdditional(examplesForModel, examplesForEnsemble, true);
218222
examplesForModel.clear(); examplesForEnsemble.clear();
219223
nExpert.additionalExamples(examplesForModel, examplesForEnsemble);
220224

221-
if (ocl::haveOpenCL())
222-
tldModel->ocl_integrateAdditional(examplesForModel, examplesForEnsemble, false);
223-
else
224-
tldModel->integrateAdditional(examplesForModel, examplesForEnsemble, false);
225+
#ifdef HAVE_OPENCL
226+
if (ocl::haveOpenCL())
227+
tldModel->ocl_integrateAdditional(examplesForModel, examplesForEnsemble, false);
228+
else
229+
#endif
230+
tldModel->integrateAdditional(examplesForModel, examplesForEnsemble, false);
225231
}
226232
else
227233
{

modules/xfeatures2d/src/surf.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,7 @@ void SURF_Impl::detectAndCompute(InputArray _img, InputArray _mask,
892892
CV_Assert(!_img.empty() && CV_MAT_DEPTH(imgtype) == CV_8U && (imgcn == 1 || imgcn == 3 || imgcn == 4));
893893
CV_Assert(_descriptors.needed() || !useProvidedKeypoints);
894894

895+
#ifdef HAVE_OPENCL
895896
if( ocl::useOpenCL() )
896897
{
897898
SURF_OCL ocl_surf;
@@ -918,6 +919,7 @@ void SURF_Impl::detectAndCompute(InputArray _img, InputArray _mask,
918919
return;
919920
}
920921
}
922+
#endif // HAVE_OPENCL
921923

922924
Mat img = _img.getMat(), mask = _mask.getMat(), mask1, sum, msum;
923925

modules/xfeatures2d/src/surf.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class SURF_Impl : public SURF
6464
bool upright;
6565
};
6666

67+
#ifdef HAVE_OPENCL
6768
class SURF_OCL
6869
{
6970
public:
@@ -145,6 +146,7 @@ class SURF_OCL
145146

146147
int status;
147148
};
149+
#endif // HAVE_OPENCL
148150

149151
/*
150152
template<typename _Tp> void copyVectorToUMat(const std::vector<_Tp>& v, UMat& um)

0 commit comments

Comments
 (0)