1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
From ac8dd366e4a1877e0af16961a4094496bed955f7 Mon Sep 17 00:00:00 2001
From: Alexander Alekhin <alexander.alekhin@itseez.com>
Date: Sun, 13 Sep 2015 21:18:47 +0300
Subject: [PATCH] ocl: fix "off" mode
diff --git opencv_contrib-master/modules/tracking/src/tldDetector.cpp opencv_contrib-master/modules/tracking/src/tldDetector.cpp
index cbb783e..d61444b 100644
--- opencv_contrib-master/modules/tracking/src/tldDetector.cpp
+++ opencv_contrib-master/modules/tracking/src/tldDetector.cpp
@@ -104,6 +104,7 @@ namespace cv
return splus / (sminus + splus);
}
+#ifdef HAVE_OPENCL
double TLDDetector::ocl_Sr(const Mat_<uchar>& patch)
{
//int64 e1, e2, e3, e4;
@@ -283,6 +284,7 @@ namespace cv
//t = (e2 - e1) / getTickFrequency()*1000.0;
//printf("Sr GPU: %f\n\n", t);
}
+#endif
// Calculate Conservative similarity of the patch (NN-Model)
double TLDDetector::Sc(const Mat_<uchar>& patch)
@@ -337,6 +339,7 @@ namespace cv
return splus / (sminus + splus);
}
+#ifdef HAVE_OPENCL
double TLDDetector::ocl_Sc(const Mat_<uchar>& patch)
{
//int64 e1, e2, e3, e4;
@@ -415,6 +418,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<Rect2d>& res, bool withScaling)
@@ -565,6 +569,7 @@ namespace cv
return true;
}
+#ifdef HAVE_OPENCL
bool TLDDetector::ocl_detect(const Mat& img, const Mat& imgBlurred, Rect2d& res, std::vector<LabeledPatch>& patches, Size initSize)
{
patches.clear();
@@ -696,6 +701,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 opencv_contrib-master/modules/tracking/src/tldDetector.hpp opencv_contrib-master/modules/tracking/src/tldDetector.hpp
index 3e11895..1caff57 100644
--- opencv_contrib-master/modules/tracking/src/tldDetector.hpp
+++ opencv_contrib-master/modules/tracking/src/tldDetector.hpp
@@ -74,10 +74,12 @@ namespace cv
inline double ensembleClassifierNum(const uchar* data);
inline void prepareClassifiers(int rowstep);
double Sr(const Mat_<uchar>& patch);
- double ocl_Sr(const Mat_<uchar>& patch);
double Sc(const Mat_<uchar>& patch);
+#ifdef HAVE_OPENCL
+ double ocl_Sr(const Mat_<uchar>& patch);
double ocl_Sc(const Mat_<uchar>& patch);
void ocl_batchSrSc(const Mat_<uchar>& patches, double *resultSr, double *resultSc, int numOfPatches);
+#endif
std::vector<TLDEnsembleClassifier> classifiers;
Mat *posExp, *negExp;
diff --git opencv_contrib-master/modules/tracking/src/tldModel.cpp opencv_contrib-master/modules/tracking/src/tldModel.cpp
index 0854022..47fc32a 100644
--- opencv_contrib-master/modules/tracking/src/tldModel.cpp
+++ opencv_contrib-master/modules/tracking/src/tldModel.cpp
@@ -246,6 +246,7 @@ namespace cv
dfprintf((stdout, "\n"));*/
}
+#ifdef HAVE_OPENCL
void TrackerTLDModel::ocl_integrateAdditional(const std::vector<Mat_<uchar> >& eForModel, const std::vector<Mat_<uchar> >& eForEnsemble, bool isPositive)
{
int positiveIntoModel = 0, negativeIntoModel = 0, positiveIntoEnsemble = 0, negativeIntoEnsemble = 0;
@@ -315,6 +316,7 @@ namespace cv
dfprintf((stdout, "positiveIntoEnsemble = %d ", positiveIntoEnsemble));
dfprintf((stdout, "\n"));*/
}
+#endif // HAVE_OPENCL
//Push the patch to the model
void TrackerTLDModel::pushIntoModel(const Mat_<uchar>& example, bool positive)
diff --git opencv_contrib-master/modules/tracking/src/tldModel.hpp opencv_contrib-master/modules/tracking/src/tldModel.hpp
index be9141a..ba7c926 100644
--- opencv_contrib-master/modules/tracking/src/tldModel.hpp
+++ opencv_contrib-master/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<TLDDetector::LabeledPatch>& patches);
void integrateAdditional(const std::vector<Mat_<uchar> >& eForModel, const std::vector<Mat_<uchar> >& eForEnsemble, bool isPositive);
+#ifdef HAVE_OPENCL
void ocl_integrateAdditional(const std::vector<Mat_<uchar> >& eForModel, const std::vector<Mat_<uchar> >& eForEnsemble, bool isPositive);
+#endif
Size getMinSize(){ return minSize_; }
void printme(FILE* port = stdout);
Ptr<TLDDetector> detector;
diff --git opencv_contrib-master/modules/tracking/src/tldTracker.cpp opencv_contrib-master/modules/tracking/src/tldTracker.cpp
index 0f1e2f7..a5190f5 100644
--- opencv_contrib-master/modules/tracking/src/tldTracker.cpp
+++ opencv_contrib-master/modules/tracking/src/tldTracker.cpp
@@ -123,9 +123,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());
}
@@ -211,17 +213,21 @@ bool TrackerTLDImpl::updateImpl(const Mat& image, Rect2d& boundingBox)
tldModel->integrateRelabeled(imageForDetector, image_blurred, detectorResults);
//dprintf(("%d relabeled by nExpert\n", negRelabeled));
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 opencv_contrib-master/modules/xfeatures2d/src/surf.cpp opencv_contrib-master/modules/xfeatures2d/src/surf.cpp
index 673817e..af5ceaf6 100644
--- opencv_contrib-master/modules/xfeatures2d/src/surf.cpp
+++ opencv_contrib-master/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 opencv_contrib-master/modules/xfeatures2d/src/surf.hpp opencv_contrib-master/modules/xfeatures2d/src/surf.hpp
index 2c4e271..cf3fda1 100644
--- opencv_contrib-master/modules/xfeatures2d/src/surf.hpp
+++ opencv_contrib-master/modules/xfeatures2d/src/surf.hpp
@@ -64,6 +64,7 @@ class SURF_Impl : public SURF
bool upright;
};
+#ifdef HAVE_OPENCL
class SURF_OCL
{
public:
@@ -145,6 +146,7 @@ class SURF_OCL
int status;
};
+#endif // HAVE_OPENCL
/*
template<typename _Tp> void copyVectorToUMat(const std::vector<_Tp>& v, UMat& um)
diff --git opencv_contrib-master/modules/xfeatures2d/src/surf.ocl.cpp opencv_contrib-master/modules/xfeatures2d/src/surf.ocl.cpp
index b12ebd3..3d9845d 100644
--- opencv_contrib-master/modules/xfeatures2d/src/surf.ocl.cpp
+++ opencv_contrib-master/modules/xfeatures2d/src/surf.ocl.cpp
@@ -43,6 +43,9 @@
//
//M*/
#include "precomp.hpp"
+
+#ifdef HAVE_OPENCL
+
#include "surf.hpp"
#include <cstdio>
@@ -461,3 +464,4 @@ bool SURF_OCL::calcOrientation(UMat &keypoints)
}
}
+#endif // HAVE_OPENCL
|