aboutsummaryrefslogtreecommitdiffstats
path: root/meta-oe/recipes-support/opencv/opencv/0001-tracking-make-opencv_dnn-dependancy-optional.patch
blob: fba43eba752a87e065acfc39c86c0cba65017f3a (plain)
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
From 69f86025978b9bbbefa54a7248316a859773aeaf Mon Sep 17 00:00:00 2001
From: berak <px1704@web.de>
Date: Sat, 4 Mar 2017 12:38:50 +0100
Subject: [PATCH] tracking: make opencv_dnn dependancy optional

Upstream-status: Backport [https://github.com/opencv/opencv_contrib/commit/43925b60d392fbd01d6b0449713f010f9babe448]
Signed-off-by: Ismo Puustinen <ismo.puustinen@intel.com>

---
 modules/tracking/CMakeLists.txt                   |  3 +--
 modules/tracking/samples/goturnTracker.cpp        | 22 +++++++++++++++++++---
 modules/tracking/samples/multiTracker_dataset.cpp |  1 +
 modules/tracking/samples/tracker_dataset.cpp      |  1 +
 modules/tracking/src/gtrTracker.cpp               | 11 ++++++++++-
 modules/tracking/src/gtrTracker.hpp               | 12 ++++++++----
 modules/tracking/src/gtrUtils.cpp                 |  6 +++---
 modules/tracking/src/gtrUtils.hpp                 |  5 ++---
 modules/tracking/src/tracker.cpp                  |  1 +
 9 files changed, 46 insertions(+), 16 deletions(-)

diff --git a/modules/tracking/CMakeLists.txt b/modules/tracking/CMakeLists.txt
index a8b3183..d27f999 100644
--- a/modules/tracking/CMakeLists.txt
+++ b/modules/tracking/CMakeLists.txt
@@ -1,2 +1 @@
-set(the_description "Tracking API")
-ocv_define_module(tracking opencv_imgproc opencv_core opencv_video opencv_highgui opencv_dnn opencv_plot OPTIONAL opencv_datasets WRAP python)
\ No newline at end of file
+ocv_define_module(tracking opencv_imgproc opencv_core opencv_video opencv_highgui opencv_plot OPTIONAL opencv_dnn opencv_datasets WRAP python)
diff --git a/modules/tracking/samples/goturnTracker.cpp b/modules/tracking/samples/goturnTracker.cpp
index 389771e..1e6632d 100644
--- a/modules/tracking/samples/goturnTracker.cpp
+++ b/modules/tracking/samples/goturnTracker.cpp
@@ -45,6 +45,9 @@
 //1 - Train you own GOTURN model using <https://github.com/Auron-X/GOTURN_Training_Toolkit>
 //2 - Download pretrained caffemodel from <https://github.com/opencv/opencv_extra>
 
+#include "opencv2/opencv_modules.hpp"
+#if defined(HAVE_OPENCV_DNN) && defined(HAVE_OPENCV_DATASETS)
+
 #include "opencv2/datasets/track_alov.hpp"
 #include <opencv2/core/utility.hpp>
 #include <opencv2/tracking.hpp>
@@ -65,8 +68,8 @@ static bool startSelection = false;
 Rect2d boundingBox;
 
 static const char* keys =
-{ "{@dataset_path     |true| Dataset path     }"
-"{@dataset_id     |1| Dataset ID     }"
+{ "{@dataset_path     || Dataset path   }"
+  "{@dataset_id      |1| Dataset ID     }"
 };
 
 static void onMouse(int event, int x, int y, int, void*)
@@ -144,9 +147,14 @@ int main(int argc, char *argv[])
     Ptr<cv::datasets::TRACK_alov> dataset = TRACK_alov::create();
     dataset->load(datasetRootPath);
     dataset->initDataset(datasetID);
-
     //Read first frame
     dataset->getNextFrame(frame);
+    if (frame.empty())
+    {
+        cout << "invalid dataset: " << datasetRootPath << endl;
+        return -2;
+    }
+
     frame.copyTo(image);
     rectangle(image, boundingBox, Scalar(255, 0, 0), 2, 1);
     imshow("GOTURN Tracking", image);
@@ -215,3 +223,11 @@ int main(int argc, char *argv[])
 
     return 0;
 }
+
+#else // ! HAVE_OPENCV_DNN && HAVE_OPENCV_DATASETS
+#include <opencv2/core.hpp>
+int main() {
+    CV_Error(cv::Error::StsNotImplemented , "this sample needs to be built with opencv_datasets and opencv_dnn !");
+    return -1;
+}
+#endif
diff --git a/modules/tracking/samples/multiTracker_dataset.cpp b/modules/tracking/samples/multiTracker_dataset.cpp
index 2826b19..b5c27da 100644
--- a/modules/tracking/samples/multiTracker_dataset.cpp
+++ b/modules/tracking/samples/multiTracker_dataset.cpp
@@ -234,6 +234,7 @@ int main(int argc, char *argv[])
 }
 
 #else // ! HAVE_OPENCV_DATASETS
+#include <opencv2/core.hpp>
 int main() {
 	CV_Error(cv::Error::StsNotImplemented , "this sample needs to be built with opencv_datasets !");
 	return -1;
diff --git a/modules/tracking/samples/tracker_dataset.cpp b/modules/tracking/samples/tracker_dataset.cpp
index 8b7832a..6178105 100644
--- a/modules/tracking/samples/tracker_dataset.cpp
+++ b/modules/tracking/samples/tracker_dataset.cpp
@@ -234,6 +234,7 @@ int main(int argc, char *argv[])
 
 
 #else // ! HAVE_OPENCV_DATASETS
+#include <opencv2/core.hpp>
 int main() {
 	CV_Error(cv::Error::StsNotImplemented , "this sample needs to be built with opencv_datasets !");
 	return -1;
diff --git a/modules/tracking/src/gtrTracker.cpp b/modules/tracking/src/gtrTracker.cpp
index 58debfd..4904f47 100644
--- a/modules/tracking/src/gtrTracker.cpp
+++ b/modules/tracking/src/gtrTracker.cpp
@@ -38,7 +38,7 @@
 // the use of this software, even if advised of the possibility of such damage.
 //
 //M*/
-
+#include "opencv2/opencv_modules.hpp"
 #include "gtrTracker.hpp"
 
 
@@ -54,9 +54,16 @@ void TrackerGOTURN::Params::write(cv::FileStorage& /*fs*/) const {}
 
 Ptr<TrackerGOTURN> TrackerGOTURN::createTracker(const TrackerGOTURN::Params &parameters)
 {
+#ifdef HAVE_OPENCV_DNN
     return Ptr<gtr::TrackerGOTURNImpl>(new gtr::TrackerGOTURNImpl(parameters));
+#else
+    (void)(parameters);
+    CV_ErrorNoReturn(cv::Error::StsNotImplemented , "to use GOTURN, the tracking module needs to be built with opencv_dnn !");
+#endif
 }
 
+
+#ifdef HAVE_OPENCV_DNN
 namespace gtr
 {
 
@@ -183,9 +190,11 @@ bool TrackerGOTURNImpl::updateImpl(const Mat& image, Rect2d& boundingBox)
     //Set new model image and BB from current frame
     ((TrackerGOTURNModel*)static_cast<TrackerModel*>(model))->setImage(curFrame);
     ((TrackerGOTURNModel*)static_cast<TrackerModel*>(model))->setBoudingBox(curBB);
+
     return true;
 }
 
 }
+#endif // OPENCV_HAVE_DNN
 
 }
diff --git a/modules/tracking/src/gtrTracker.hpp b/modules/tracking/src/gtrTracker.hpp
index 34f2c48..21ae3d9 100644
--- a/modules/tracking/src/gtrTracker.hpp
+++ b/modules/tracking/src/gtrTracker.hpp
@@ -45,11 +45,15 @@
 
 #include "precomp.hpp"
 #include "opencv2/video/tracking.hpp"
-#include "opencv2/dnn.hpp"
 #include "gtrUtils.hpp"
 #include "opencv2/imgproc.hpp"
-#include<algorithm>
-#include<limits.h>
+
+#include <algorithm>
+#include <limits.h>
+
+#include "opencv2/opencv_modules.hpp"
+#ifdef HAVE_OPENCV_DNN
+#include "opencv2/dnn.hpp"
 
 namespace cv
 {
@@ -72,5 +76,5 @@ public:
 
 }
 }
-
+#endif
 #endif
diff --git a/modules/tracking/src/gtrUtils.cpp b/modules/tracking/src/gtrUtils.cpp
index 0df1197..e80dda1 100644
--- a/modules/tracking/src/gtrUtils.cpp
+++ b/modules/tracking/src/gtrUtils.cpp
@@ -58,7 +58,7 @@ double generateRandomLaplacian(double b, double m)
         return m - b*log(n);
 }
 
-Rect2f anno2rect(vector<Point2f> annoBB)
+Rect2f anno2rect(std::vector<Point2f> annoBB)
 {
     Rect2f rectBB;
     rectBB.x = min(annoBB[0].x, annoBB[1].x);
@@ -69,9 +69,9 @@ Rect2f anno2rect(vector<Point2f> annoBB)
     return rectBB;
 }
 
-vector <TrainingSample> gatherFrameSamples(Mat prevFrame, Mat currFrame, Rect2f prevBB, Rect2f currBB)
+std::vector <TrainingSample> gatherFrameSamples(Mat prevFrame, Mat currFrame, Rect2f prevBB, Rect2f currBB)
 {
-    vector <TrainingSample> trainingSamples;
+    std::vector <TrainingSample> trainingSamples;
     Point2f currCenter, prevCenter;
     Rect2f targetPatchRect, searchPatchRect;
     Mat targetPatch, searchPatch;
diff --git a/modules/tracking/src/gtrUtils.hpp b/modules/tracking/src/gtrUtils.hpp
index 8f388be..41aad21 100644
--- a/modules/tracking/src/gtrUtils.hpp
+++ b/modules/tracking/src/gtrUtils.hpp
@@ -4,7 +4,6 @@
 #include "precomp.hpp"
 #include <vector>
 #include "opencv2/highgui.hpp"
-#include <opencv2/datasets/track_alov.hpp>
 
 namespace cv
 {
@@ -50,10 +49,10 @@ struct TrainingSample
 double generateRandomLaplacian(double b, double m);
 
 //Convert ALOV300++ anno coordinates to Rectangle BB
-Rect2f anno2rect(vector<Point2f> annoBB);
+Rect2f anno2rect(std::vector<Point2f> annoBB);
 
 //Gather samples from random video frame
-vector <TrainingSample> gatherFrameSamples(Mat prevFrame, Mat currFrame, Rect2f prevBB, Rect2f currBB);
+std::vector <TrainingSample> gatherFrameSamples(Mat prevFrame, Mat currFrame, Rect2f prevBB, Rect2f currBB);
 
 }
 }
diff --git a/modules/tracking/src/tracker.cpp b/modules/tracking/src/tracker.cpp
index 8127f2a..b96aca8 100644
--- a/modules/tracking/src/tracker.cpp
+++ b/modules/tracking/src/tracker.cpp
@@ -112,6 +112,7 @@ Ptr<Tracker> Tracker::create( const String& trackerType )
   BOILERPLATE_CODE("TLD",TrackerTLD);
   BOILERPLATE_CODE("KCF",TrackerKCF);
   BOILERPLATE_CODE("GOTURN", TrackerGOTURN);
+
   return Ptr<Tracker>();
 }
 
-- 
2.9.4