Skip to content

Commit e9a5780

Browse files
committed
Refactor Tracking group all legacy in a single file
1 parent d81a9c7 commit e9a5780

35 files changed

+796
-969
lines changed

binding.gyp

+2-11
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,10 @@
8181
"cc/tracking/tracking.cc",
8282
"cc/tracking/Tracker.cc",
8383
"cc/tracking/MultiTracker.cc",
84-
"cc/tracking/Trackers/TrackerBoosting.cc",
85-
"cc/tracking/Trackers/TrackerBoostingParams.cc",
86-
"cc/tracking/Trackers/TrackerKCF.cc",
87-
"cc/tracking/Trackers/TrackerKCFParams.cc",
88-
"cc/tracking/Trackers/TrackerMIL.cc",
89-
"cc/tracking/Trackers/TrackerMILParams.cc",
90-
"cc/tracking/Trackers/TrackerMedianFlow.cc",
91-
"cc/tracking/Trackers/TrackerTLD.cc",
84+
"cc/tracking/Trackers/TrackerLegacy.cc",
85+
"cc/tracking/Trackers/TrackerLegacyParams.cc",
9286
"cc/tracking/Trackers/TrackerGOTURN.cc",
9387
"cc/tracking/Trackers/TrackerNano.cc",
94-
"cc/tracking/Trackers/TrackerCSRT.cc",
95-
"cc/tracking/Trackers/TrackerCSRTParams.cc",
96-
"cc/tracking/Trackers/TrackerMOSSE.cc",
9788
"cc/features2d/features2d.cc",
9889
"cc/features2d/KeyPoint.cc",
9990
"cc/features2d/KeyPointMatch.cc",

binding_old.gyp

+2-11
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,10 @@
8181
"cc/tracking/tracking.cc",
8282
"cc/tracking/Tracker.cc",
8383
"cc/tracking/MultiTracker.cc",
84-
"cc/tracking/Trackers/TrackerBoosting.cc",
85-
"cc/tracking/Trackers/TrackerBoostingParams.cc",
86-
"cc/tracking/Trackers/TrackerKCF.cc",
87-
"cc/tracking/Trackers/TrackerKCFParams.cc",
88-
"cc/tracking/Trackers/TrackerMIL.cc",
89-
"cc/tracking/Trackers/TrackerMILParams.cc",
90-
"cc/tracking/Trackers/TrackerMedianFlow.cc",
91-
"cc/tracking/Trackers/TrackerTLD.cc",
84+
"cc/tracking/Trackers/TrackerLegacy.cc",
85+
"cc/tracking/Trackers/TrackerLegacyParams.cc",
9286
"cc/tracking/Trackers/TrackerGOTURN.cc",
9387
"cc/tracking/Trackers/TrackerNano.cc",
94-
"cc/tracking/Trackers/TrackerCSRT.cc",
95-
"cc/tracking/Trackers/TrackerCSRTParams.cc",
96-
"cc/tracking/Trackers/TrackerMOSSE.cc",
9788
"cc/features2d/features2d.cc",
9889
"cc/features2d/KeyPoint.cc",
9990
"cc/features2d/KeyPointMatch.cc",

cc/tracking/MultiTracker.cc

+23-22
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ NAN_MODULE_INIT(MultiTracker::Init) {
2323
Nan::SetPrototypeMethod(ctor, "addKCF", MultiTracker::AddKCF);
2424
#if CV_VERSION_GREATER_EQUAL(3, 4, 0)
2525
Nan::SetPrototypeMethod(ctor, "addMOSSE", MultiTracker::AddTLD);
26-
#endif
26+
#endif // CV_VERSION_GREATER_EQUAL(3, 4, 0)
2727
#if CV_VERSION_GREATER_EQUAL(3, 4, 1)
2828
Nan::SetPrototypeMethod(ctor, "addCSRT", MultiTracker::AddKCF);
29-
#endif
29+
#endif // CV_VERSION_GREATER_EQUAL(3, 4, 1)
3030
Nan::SetPrototypeMethod(ctor, "update", MultiTracker::Update);
3131

3232
Nan::Set(target, FF::newString("MultiTracker"), FF::getFunction(ctor));
@@ -38,9 +38,9 @@ NAN_METHOD(MultiTracker::New) {
3838
MultiTracker* self = new MultiTracker();
3939
#if CV_VERSION_GREATER_EQUAL(4, 5, 2)
4040
self->setNativeObject(cv::makePtr<cv::legacy::MultiTracker>());
41-
#else
41+
#else // CV_VERSION_GREATER_EQUAL(4, 5, 2)
4242
self->setNativeObject(cv::makePtr<cv::MultiTracker>());
43-
#endif
43+
#endif // CV_VERSION_GREATER_EQUAL(4, 5, 2)
4444
self->Wrap(info.Holder());
4545
info.GetReturnValue().Set(info.Holder());
4646
};
@@ -57,9 +57,9 @@ NAN_METHOD(MultiTracker::AddMIL) {
5757
cv::Ptr<cv::legacy::Tracker> type = cv::legacy::TrackerMIL::create();
5858
#elif CV_VERSION_GREATER_EQUAL(3, 3, 0)
5959
cv::Ptr<cv::Tracker> type = cv::TrackerMIL::create();
60-
#else
60+
#else // CV_VERSION_GREATER_EQUAL(3, 3, 0)
6161
const std::string type("MIL");
62-
#endif
62+
#endif // CV_VERSION_GREATER_EQUAL(4, 5, 2)
6363
bool ret = MultiTracker::unwrapSelf(info)->add(type, image, boundingBox);
6464
info.GetReturnValue().Set(Nan::New(ret));
6565
}
@@ -76,9 +76,9 @@ NAN_METHOD(MultiTracker::AddBOOSTING) {
7676
cv::Ptr<cv::legacy::Tracker> type = cv::legacy::TrackerBoosting::create();
7777
#elif CV_VERSION_GREATER_EQUAL(3, 3, 0)
7878
cv::Ptr<cv::Tracker> type = cv::TrackerBoosting::create();
79-
#else
79+
#else // CV_VERSION_GREATER_EQUAL(3, 3, 0)
8080
const std::string type("BOOSTING");
81-
#endif
81+
#endif // CV_VERSION_GREATER_EQUAL(4, 5, 2)
8282
bool ret = MultiTracker::unwrapSelf(info)->add(type, image, boundingBox);
8383
info.GetReturnValue().Set(Nan::New(ret));
8484
}
@@ -95,9 +95,9 @@ NAN_METHOD(MultiTracker::AddMEDIANFLOW) {
9595
cv::Ptr<cv::legacy::Tracker> type = cv::legacy::TrackerMedianFlow::create();
9696
#elif CV_VERSION_GREATER_EQUAL(3, 3, 0)
9797
cv::Ptr<cv::Tracker> type = cv::TrackerMedianFlow::create();
98-
#else
98+
#else // CV_VERSION_GREATER_EQUAL(3, 3, 0)
9999
const std::string type("MEDIANFLOW");
100-
#endif
100+
#endif // CV_VERSION_GREATER_EQUAL(4, 5, 2)
101101
bool ret = MultiTracker::unwrapSelf(info)->add(type, image, boundingBox);
102102
info.GetReturnValue().Set(Nan::New(ret));
103103
}
@@ -114,9 +114,9 @@ NAN_METHOD(MultiTracker::AddTLD) {
114114
cv::Ptr<cv::legacy::Tracker> type = cv::legacy::TrackerTLD::create();
115115
#elif CV_VERSION_GREATER_EQUAL(3, 3, 0)
116116
cv::Ptr<cv::Tracker> type = cv::TrackerTLD::create();
117-
#else
117+
#else // CV_VERSION_GREATER_EQUAL(3, 3, 0)
118118
const std::string type("TLD");
119-
#endif
119+
#endif // CV_VERSION_GREATER_EQUAL(4, 5, 2)
120120
bool ret = MultiTracker::unwrapSelf(info)->add(type, image, boundingBox);
121121
info.GetReturnValue().Set(Nan::New(ret));
122122
}
@@ -133,9 +133,9 @@ NAN_METHOD(MultiTracker::AddKCF) {
133133
cv::Ptr<cv::legacy::Tracker> type = cv::legacy::TrackerKCF::create();
134134
#elif CV_VERSION_GREATER_EQUAL(3, 3, 0)
135135
cv::Ptr<cv::Tracker> type = cv::TrackerKCF::create();
136-
#else
136+
#else // CV_VERSION_GREATER_EQUAL(3, 3, 0)
137137
const std::string type("KCF");
138-
#endif
138+
#endif // CV_VERSION_GREATER_EQUAL(4, 5, 2)
139139
bool ret = MultiTracker::unwrapSelf(info)->add(type, image, boundingBox);
140140
info.GetReturnValue().Set(Nan::New(ret));
141141
}
@@ -151,6 +151,7 @@ NAN_METHOD(MultiTracker::Update) {
151151
MultiTracker::unwrapSelf(info)->update(image, rects);
152152
info.GetReturnValue().Set(Rect::ArrayConverter::wrap(rects));
153153
}
154+
154155
#if CV_VERSION_GREATER_EQUAL(3, 4, 0)
155156

156157
NAN_METHOD(MultiTracker::AddMOSSE) {
@@ -163,14 +164,14 @@ NAN_METHOD(MultiTracker::AddMOSSE) {
163164
}
164165
#if CV_VERSION_GREATER_EQUAL(4, 5, 2)
165166
cv::Ptr<cv::legacy::Tracker> type = cv::legacy::TrackerMOSSE::create();
166-
#else
167+
#else // CV_VERSION_GREATER_EQUAL(4, 5, 2)
167168
cv::Ptr<cv::Tracker> type = cv::TrackerMOSSE::create();
168-
#endif
169+
#endif // CV_VERSION_GREATER_EQUAL(4, 5, 2)
169170
bool ret = MultiTracker::unwrapSelf(info)->add(type, image, boundingBox);
170171
info.GetReturnValue().Set(Nan::New(ret));
171172
}
173+
#endif // CV_VERSION_GREATER_EQUAL(3, 4, 0)
172174

173-
#endif
174175
#if CV_VERSION_GREATER_EQUAL(3, 4, 1)
175176

176177
NAN_METHOD(MultiTracker::AddCSRT) {
@@ -183,14 +184,14 @@ NAN_METHOD(MultiTracker::AddCSRT) {
183184
}
184185
#if CV_VERSION_GREATER_EQUAL(4, 5, 2)
185186
cv::Ptr<cv::legacy::Tracker> type = cv::legacy::TrackerCSRT::create();
186-
#else
187+
#else // CV_VERSION_GREATER_EQUAL(4, 5, 2)
187188
cv::Ptr<cv::Tracker> type = cv::TrackerCSRT::create();
188-
#endif
189+
#endif // CV_VERSION_GREATER_EQUAL(4, 5, 2)
189190
bool ret = MultiTracker::unwrapSelf(info)->add(type, image, boundingBox);
190191
info.GetReturnValue().Set(Nan::New(ret));
191192
}
192-
#endif
193+
#endif // CV_VERSION_GREATER_EQUAL(3, 4, 1)
193194

194-
#endif
195+
#endif // CV_VERSION_GREATER_EQUAL(3, 1, 0)
195196

196-
#endif
197+
#endif // HAVE_OPENCV_TRACKING

cc/tracking/MultiTracker.h

+9-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <opencv2/tracking.hpp>
33
#if CV_VERSION_GREATER_EQUAL(4, 5, 2)
44
#include <opencv2/tracking/tracking_legacy.hpp>
5-
#endif
5+
#endif // CV_VERSION_GREATER_EQUAL(4, 5, 2)
66
#include "Mat.h"
77
#include "Rect.h"
88

@@ -11,11 +11,13 @@
1111
#ifndef __FF_MULTITRACKER_H__
1212
#define __FF_MULTITRACKER_H__
1313

14+
class MultiTracker
1415
#if CV_VERSION_GREATER_EQUAL(4, 5, 2)
15-
class MultiTracker : public FF::ObjectWrap<MultiTracker, cv::Ptr<cv::legacy::MultiTracker>> {
16-
#else
17-
class MultiTracker : public FF::ObjectWrap<MultiTracker, cv::Ptr<cv::MultiTracker>> {
18-
#endif
16+
: public FF::ObjectWrap<MultiTracker, cv::Ptr<cv::legacy::MultiTracker>>
17+
#else // CV_VERSION_GREATER_EQUAL(4, 5, 2)
18+
: public FF::ObjectWrap<MultiTracker, cv::Ptr<cv::MultiTracker>>
19+
#endif // CV_VERSION_GREATER_EQUAL(4, 5, 2)
20+
{
1921
public:
2022
static Nan::Persistent<v8::FunctionTemplate> constructor;
2123

@@ -36,6 +38,6 @@ class MultiTracker : public FF::ObjectWrap<MultiTracker, cv::Ptr<cv::MultiTracke
3638
static NAN_METHOD(Update);
3739
};
3840

39-
#endif
41+
#endif // __FF_MULTITRACKER_H__
4042

41-
#endif
43+
#endif // CV_VERSION_GREATER_EQUAL(3, 1, 0)

cc/tracking/Tracker.cc

+8-4
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@ NAN_METHOD(Tracker::Init) {
1919
FF::TryCatch tryCatch("Tracker::Init");
2020
cv::Mat image;
2121
cv::Rect2d boundingBox;
22-
if (
23-
Mat::Converter::arg(0, &image, info) || Rect::Converter::arg(1, &boundingBox, info)) {
22+
if (Mat::Converter::arg(0, &image, info) || Rect::Converter::arg(1, &boundingBox, info)) {
2423
return tryCatch.reThrow();
2524
}
2625

27-
bool ret = Tracker::unwrapThis(info)->getTracker()->init(image, boundingBox);
28-
info.GetReturnValue().Set(Nan::New(ret));
26+
try {
27+
bool ret = Tracker::unwrapThis(info)->getTracker()->init(image, boundingBox);
28+
// If no error is thrown, return true
29+
info.GetReturnValue().Set(Nan::New(ret));
30+
} catch (const std::exception& e) {
31+
return tryCatch.throwError(e.what());
32+
}
2933
}
3034

3135
NAN_METHOD(Tracker::Update) {

cc/tracking/Trackers/TrackerBoosting.cc

-49
This file was deleted.

cc/tracking/Trackers/TrackerBoosting.h

-30
This file was deleted.

cc/tracking/Trackers/TrackerBoostingParams.cc

-39
This file was deleted.

cc/tracking/Trackers/TrackerBoostingParams.h

-33
This file was deleted.

0 commit comments

Comments
 (0)