Skip to content

Commit 06b03a7

Browse files
committed
Merge pull request #372 from alalek:ocl_off
2 parents bf699c3 + ac8dd36 commit 06b03a7

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
@@ -83,6 +83,7 @@ namespace cv
8383
return splus / (sminus + splus);
8484
}
8585

86+
#ifdef HAVE_OPENCL
8687
double TLDDetector::ocl_Sr(const Mat_<uchar>& patch)
8788
{
8889
double splus = 0.0, sminus = 0.0;
@@ -185,6 +186,7 @@ namespace cv
185186
resultSc[id] = spc / (smc + spc);
186187
}
187188
}
189+
#endif
188190

189191
// Calculate Conservative similarity of the patch (NN-Model)
190192
double TLDDetector::Sc(const Mat_<uchar>& patch)
@@ -212,6 +214,7 @@ namespace cv
212214
return splus / (sminus + splus);
213215
}
214216

217+
#ifdef HAVE_OPENCL
215218
double TLDDetector::ocl_Sc(const Mat_<uchar>& patch)
216219
{
217220
double splus = 0.0, sminus = 0.0;
@@ -256,6 +259,7 @@ namespace cv
256259
return 0.0;
257260
return splus / (sminus + splus);
258261
}
262+
#endif // HAVE_OPENCL
259263

260264
// Generate Search Windows for detector from aspect ratio of initial BBs
261265
void TLDDetector::generateScanGrid(int rows, int cols, Size initBox, std::vector<Rect2d>& res, bool withScaling)
@@ -393,6 +397,7 @@ namespace cv
393397
}
394398
}
395399

400+
#ifdef HAVE_OPENCL
396401
bool TLDDetector::ocl_detect(const Mat& img, const Mat& imgBlurred, Rect2d& res, std::vector<LabeledPatch>& patches, Size initSize)
397402
{
398403
patches.clear();
@@ -507,6 +512,7 @@ namespace cv
507512
res = maxScRect;
508513
return true;
509514
}
515+
#endif // HAVE_OPENCL
510516

511517
// Computes the variance of subimage given by box, with the help of two integral
512518
// 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
@@ -76,10 +76,12 @@ namespace cv
7676
double ensembleClassifierNum(const uchar* data);
7777
void prepareClassifiers(int rowstep);
7878
double Sr(const Mat_<uchar>& patch);
79-
double ocl_Sr(const Mat_<uchar>& patch);
8079
double Sc(const Mat_<uchar>& patch);
80+
#ifdef HAVE_OPENCL
81+
double ocl_Sr(const Mat_<uchar>& patch);
8182
double ocl_Sc(const Mat_<uchar>& patch);
8283
void ocl_batchSrSc(const Mat_<uchar>& patches, double *resultSr, double *resultSc, int numOfPatches);
84+
#endif
8385

8486
std::vector<TLDEnsembleClassifier> classifiers;
8587
Mat *posExp, *negExp;

modules/tracking/src/tldModel.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ namespace cv
219219
}
220220
}
221221

222+
#ifdef HAVE_OPENCL
222223
void TrackerTLDModel::ocl_integrateAdditional(const std::vector<Mat_<uchar> >& eForModel, const std::vector<Mat_<uchar> >& eForEnsemble, bool isPositive)
223224
{
224225
int positiveIntoModel = 0, negativeIntoModel = 0, positiveIntoEnsemble = 0, negativeIntoEnsemble = 0;
@@ -271,6 +272,7 @@ namespace cv
271272
}
272273
}
273274
}
275+
#endif // HAVE_OPENCL
274276

275277
//Push the patch to the model
276278
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
@@ -129,9 +129,11 @@ bool TrackerTLDImpl::updateImpl(const Mat& image, Rect2d& boundingBox)
129129

130130
if (i == 1)
131131
{
132+
#ifdef HAVE_OPENCL
132133
if (ocl::haveOpenCL())
133134
DETECT_FLG = tldModel->detector->ocl_detect(imageForDetector, image_blurred, tmpCandid, detectorResults, tldModel->getMinSize());
134135
else
136+
#endif
135137
DETECT_FLG = tldModel->detector->detect(imageForDetector, image_blurred, tmpCandid, detectorResults, tldModel->getMinSize());
136138
}
137139
if( ( (i == 0) && !data->failedLastTime && trackerProxy->update(image, tmpCandid) ) || ( DETECT_FLG))
@@ -199,17 +201,21 @@ bool TrackerTLDImpl::updateImpl(const Mat& image, Rect2d& boundingBox)
199201
}
200202
tldModel->integrateRelabeled(imageForDetector, image_blurred, detectorResults);
201203
pExpert.additionalExamples(examplesForModel, examplesForEnsemble);
202-
if (ocl::haveOpenCL())
203-
tldModel->ocl_integrateAdditional(examplesForModel, examplesForEnsemble, true);
204-
else
205-
tldModel->integrateAdditional(examplesForModel, examplesForEnsemble, true);
204+
#ifdef HAVE_OPENCL
205+
if (ocl::haveOpenCL())
206+
tldModel->ocl_integrateAdditional(examplesForModel, examplesForEnsemble, true);
207+
else
208+
#endif
209+
tldModel->integrateAdditional(examplesForModel, examplesForEnsemble, true);
206210
examplesForModel.clear(); examplesForEnsemble.clear();
207211
nExpert.additionalExamples(examplesForModel, examplesForEnsemble);
208212

209-
if (ocl::haveOpenCL())
210-
tldModel->ocl_integrateAdditional(examplesForModel, examplesForEnsemble, false);
211-
else
212-
tldModel->integrateAdditional(examplesForModel, examplesForEnsemble, false);
213+
#ifdef HAVE_OPENCL
214+
if (ocl::haveOpenCL())
215+
tldModel->ocl_integrateAdditional(examplesForModel, examplesForEnsemble, false);
216+
else
217+
#endif
218+
tldModel->integrateAdditional(examplesForModel, examplesForEnsemble, false);
213219
}
214220
else
215221
{

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)