Skip to content

Commit

Permalink
add support to Opencv4.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
wandenberg committed Nov 9, 2021
1 parent 0aac05f commit 91bc118
Show file tree
Hide file tree
Showing 21 changed files with 228 additions and 23 deletions.
32 changes: 27 additions & 5 deletions cc/tracking/MultiTracker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ NAN_METHOD(MultiTracker::New) {
FF::TryCatch tryCatch("MultiTracker::New");
FF_ASSERT_CONSTRUCT_CALL();
MultiTracker* self = new MultiTracker();
#if CV_VERSION_GREATER_EQUAL(4, 5, 2)
self->setNativeObject(cv::makePtr<cv::legacy::MultiTracker>());
#else
self->setNativeObject(cv::makePtr<cv::MultiTracker>());
#endif
self->Wrap(info.Holder());
info.GetReturnValue().Set(info.Holder());
};
Expand All @@ -51,7 +55,9 @@ NAN_METHOD(MultiTracker::AddMIL) {
) {
return tryCatch.reThrow();
}
#if CV_VERSION_GREATER_EQUAL(3, 3, 0)
#if CV_VERSION_GREATER_EQUAL(4, 5, 2)
cv::Ptr<cv::legacy::Tracker> type = cv::legacy::TrackerMIL::create();
#elif CV_VERSION_GREATER_EQUAL(3, 3, 0)
cv::Ptr<cv::Tracker> type = cv::TrackerMIL::create();
#else
const std::string type("MIL");
Expand All @@ -70,7 +76,9 @@ NAN_METHOD(MultiTracker::AddBOOSTING) {
) {
return tryCatch.reThrow();
}
#if CV_VERSION_GREATER_EQUAL(3, 3, 0)
#if CV_VERSION_GREATER_EQUAL(4, 5, 2)
cv::Ptr<cv::legacy::Tracker> type = cv::legacy::TrackerBoosting::create();
#elif CV_VERSION_GREATER_EQUAL(3, 3, 0)
cv::Ptr<cv::Tracker> type = cv::TrackerBoosting::create();
#else
const std::string type("BOOSTING");
Expand All @@ -89,7 +97,9 @@ NAN_METHOD(MultiTracker::AddMEDIANFLOW) {
) {
return tryCatch.reThrow();
}
#if CV_VERSION_GREATER_EQUAL(3, 3, 0)
#if CV_VERSION_GREATER_EQUAL(4, 5, 2)
cv::Ptr<cv::legacy::Tracker> type = cv::legacy::TrackerMedianFlow::create();
#elif CV_VERSION_GREATER_EQUAL(3, 3, 0)
cv::Ptr<cv::Tracker> type = cv::TrackerMedianFlow::create();
#else
const std::string type("MEDIANFLOW");
Expand All @@ -108,7 +118,9 @@ NAN_METHOD(MultiTracker::AddTLD) {
) {
return tryCatch.reThrow();
}
#if CV_VERSION_GREATER_EQUAL(3, 3, 0)
#if CV_VERSION_GREATER_EQUAL(4, 5, 2)
cv::Ptr<cv::legacy::Tracker> type = cv::legacy::TrackerTLD::create();
#elif CV_VERSION_GREATER_EQUAL(3, 3, 0)
cv::Ptr<cv::Tracker> type = cv::TrackerTLD::create();
#else
const std::string type("TLD");
Expand All @@ -127,7 +139,9 @@ NAN_METHOD(MultiTracker::AddKCF) {
) {
return tryCatch.reThrow();
}
#if CV_VERSION_GREATER_EQUAL(3, 3, 0)
#if CV_VERSION_GREATER_EQUAL(4, 5, 2)
cv::Ptr<cv::legacy::Tracker> type = cv::legacy::TrackerKCF::create();
#elif CV_VERSION_GREATER_EQUAL(3, 3, 0)
cv::Ptr<cv::Tracker> type = cv::TrackerKCF::create();
#else
const std::string type("KCF");
Expand Down Expand Up @@ -159,7 +173,11 @@ NAN_METHOD(MultiTracker::AddMOSSE) {
) {
return tryCatch.reThrow();
}
#if CV_VERSION_GREATER_EQUAL(4, 5, 2)
cv::Ptr<cv::legacy::Tracker> type = cv::legacy::TrackerMOSSE::create();
#else
cv::Ptr<cv::Tracker> type = cv::TrackerMOSSE::create();
#endif
bool ret = MultiTracker::unwrapSelf(info)->add(type, image, boundingBox);
info.GetReturnValue().Set(Nan::New(ret));
}
Expand All @@ -177,7 +195,11 @@ NAN_METHOD(MultiTracker::AddCSRT) {
) {
return tryCatch.reThrow();
}
#if CV_VERSION_GREATER_EQUAL(4, 5, 2)
cv::Ptr<cv::legacy::Tracker> type = cv::legacy::TrackerCSRT::create();
#else
cv::Ptr<cv::Tracker> type = cv::TrackerCSRT::create();
#endif
bool ret = MultiTracker::unwrapSelf(info)->add(type, image, boundingBox);
info.GetReturnValue().Set(Nan::New(ret));
}
Expand Down
9 changes: 8 additions & 1 deletion cc/tracking/MultiTracker.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "macros.h"
#include <opencv2/tracking.hpp>
#if CV_VERSION_GREATER_EQUAL(4, 5, 2)
#include <opencv2/tracking/tracking_legacy.hpp>
#endif
#include "Mat.h"
#include "Rect.h"

Expand All @@ -8,7 +11,11 @@
#ifndef __FF_MULTITRACKER_H__
#define __FF_MULTITRACKER_H__

#if CV_VERSION_GREATER_EQUAL(4, 5, 2)
class MultiTracker : public FF::ObjectWrap<MultiTracker, cv::Ptr<cv::legacy::MultiTracker>> {
#else
class MultiTracker : public FF::ObjectWrap<MultiTracker, cv::Ptr<cv::MultiTracker>> {
#endif
public:
static Nan::Persistent<v8::FunctionTemplate> constructor;

Expand All @@ -31,4 +38,4 @@ class MultiTracker : public FF::ObjectWrap<MultiTracker, cv::Ptr<cv::MultiTracke

#endif

#endif
#endif
9 changes: 8 additions & 1 deletion cc/tracking/Tracker.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "macros.h"
#include <opencv2/tracking.hpp>
#if CV_VERSION_GREATER_EQUAL(4, 5, 2)
#include <opencv2/tracking/tracking_legacy.hpp>
#endif
#include "Mat.h"
#include "Rect.h"

Expand All @@ -8,7 +11,11 @@

class Tracker : public FF::ObjectWrapBase<Tracker>, public Nan::ObjectWrap {
public:
#if CV_VERSION_GREATER_EQUAL(4, 5, 2)
virtual cv::Ptr<cv::legacy::Tracker> getTracker() = 0;
#else
virtual cv::Ptr<cv::Tracker> getTracker() = 0;
#endif

static void Init(v8::Local<v8::FunctionTemplate>);

Expand All @@ -18,4 +25,4 @@ class Tracker : public FF::ObjectWrapBase<Tracker>, public Nan::ObjectWrap {
static NAN_METHOD(GetModel);
};

#endif
#endif
8 changes: 7 additions & 1 deletion cc/tracking/Trackers/TrackerBoosting.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,19 @@ NAN_METHOD(TrackerBoosting::New) {
FF::TryCatch tryCatch("TrackerBoosting::New");
FF_ASSERT_CONSTRUCT_CALL();

#if CV_VERSION_GREATER_EQUAL(4, 5, 2)
cv::legacy::TrackerBoosting::Params params;
#else
cv::TrackerBoosting::Params params;
#endif
if (TrackerBoostingParams::Converter::optArg(0, &params, info)) {
return tryCatch.reThrow();
}

TrackerBoosting* self = new TrackerBoosting();
#if CV_VERSION_GREATER_EQUAL(3, 3, 0)
#if CV_VERSION_GREATER_EQUAL(4, 5, 2)
self->tracker = cv::legacy::TrackerBoosting::create(params);
#elif CV_VERSION_GREATER_EQUAL(3, 3, 0)
self->tracker = cv::TrackerBoosting::create(params);
#else
self->tracker = cv::TrackerBoosting::createTracker(params);
Expand Down
10 changes: 9 additions & 1 deletion cc/tracking/Trackers/TrackerBoosting.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,24 @@

class TrackerBoosting : public Tracker {
public:
#if CV_VERSION_GREATER_EQUAL(4, 5, 2)
cv::Ptr<cv::legacy::TrackerBoosting> tracker;
#else
cv::Ptr<cv::TrackerBoosting> tracker;
#endif

static NAN_MODULE_INIT(Init);
static NAN_METHOD(New);

static Nan::Persistent<v8::FunctionTemplate> constructor;

#if CV_VERSION_GREATER_EQUAL(4, 5, 2)
cv::Ptr<cv::legacy::Tracker> getTracker() {
#else
cv::Ptr<cv::Tracker> getTracker() {
#endif
return tracker;
}
};

#endif
#endif
4 changes: 4 additions & 0 deletions cc/tracking/Trackers/TrackerBoostingParams.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ NAN_METHOD(TrackerBoostingParams::New) {
FF::TryCatch tryCatch("TrackerBoostingParams::New");
FF_ASSERT_CONSTRUCT_CALL();
TrackerBoostingParams* self = new TrackerBoostingParams();
#if CV_VERSION_GREATER_EQUAL(4, 5, 2)
self->self = cv::legacy::TrackerBoosting::Params();
#else
self->self = cv::TrackerBoosting::Params();
#endif
self->Wrap(info.Holder());
info.GetReturnValue().Set(info.Holder());
};
Expand Down
9 changes: 8 additions & 1 deletion cc/tracking/Trackers/TrackerBoostingParams.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
#include "macros.h"
#include <opencv2/tracking.hpp>
#if CV_VERSION_GREATER_EQUAL(4, 5, 2)
#include <opencv2/tracking/tracking_legacy.hpp>
#endif

#ifndef __FF_TRACKERBOOSTINGPARAMS_H__
#define __FF_TRACKERBOOSTINGPARAMS_H__

#if CV_VERSION_GREATER_EQUAL(4, 5, 2)
class TrackerBoostingParams : public FF::ObjectWrap<TrackerBoostingParams, cv::legacy::TrackerBoosting::Params> {
#else
class TrackerBoostingParams : public FF::ObjectWrap<TrackerBoostingParams, cv::TrackerBoosting::Params> {
#endif
public:
static Nan::Persistent<v8::FunctionTemplate> constructor;

Expand All @@ -22,4 +29,4 @@ class TrackerBoostingParams : public FF::ObjectWrap<TrackerBoostingParams, cv::T
FF_ACCESSORS(featureSetNumFeatures, FF::IntConverter);
};

#endif
#endif
8 changes: 8 additions & 0 deletions cc/tracking/Trackers/TrackerCSRT.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,21 @@ NAN_METHOD(TrackerCSRT::New) {
FF::TryCatch tryCatch("TrackerCSRT::New");
FF_ASSERT_CONSTRUCT_CALL();

#if CV_VERSION_GREATER_EQUAL(4, 5, 2)
cv::legacy::TrackerCSRT::Params params;
#else
cv::TrackerCSRT::Params params;
#endif
if (TrackerCSRTParams::Converter::optArg(0, &params, info)) {
return tryCatch.reThrow();
}

TrackerCSRT* self = new TrackerCSRT();
#if CV_VERSION_GREATER_EQUAL(4, 5, 2)
self->tracker = cv::legacy::TrackerCSRT::create(params);
#else
self->tracker = cv::TrackerCSRT::create(params);
#endif
self->Wrap(info.Holder());
info.GetReturnValue().Set(info.Holder());
};
Expand Down
10 changes: 9 additions & 1 deletion cc/tracking/Trackers/TrackerCSRT.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,26 @@

class TrackerCSRT : public Tracker {
public:
#if CV_VERSION_GREATER_EQUAL(4, 5, 2)
cv::Ptr<cv::legacy::TrackerCSRT> tracker;
#else
cv::Ptr<cv::TrackerCSRT> tracker;
#endif

static NAN_MODULE_INIT(Init);
static NAN_METHOD(New);

static Nan::Persistent<v8::FunctionTemplate> constructor;

#if CV_VERSION_GREATER_EQUAL(4, 5, 2)
cv::Ptr<cv::legacy::Tracker> getTracker() {
#else
cv::Ptr<cv::Tracker> getTracker() {
#endif
return tracker;
}
};

#endif

#endif
#endif
57 changes: 56 additions & 1 deletion cc/tracking/Trackers/TrackerGOTURN.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,67 @@

Nan::Persistent<v8::FunctionTemplate> TrackerGOTURN::constructor;

#if CV_VERSION_GREATER_EQUAL(4, 5, 2)

NAN_METHOD(TrackerGOTURN::Clear) {
}

NAN_METHOD(TrackerGOTURN::Init) {
FF::TryCatch tryCatch("TrackerGOTURN::Init");
cv::Mat image;
cv::Rect2d boundingBox;
if (
Mat::Converter::arg(0, &image, info) ||
Rect::Converter::arg(1, &boundingBox, info)
) {
return tryCatch.reThrow();
}

TrackerGOTURN::unwrapThis(info)->getTracker()->init(image, boundingBox);
}

NAN_METHOD(TrackerGOTURN::Update) {
FF::TryCatch tryCatch("TrackerGOTURN::Update");
cv::Mat image;
if (Mat::Converter::arg(0, &image, info)) {
return tryCatch.reThrow();
}

cv::Rect rect;
bool ret = false;

try {
ret = TrackerGOTURN::unwrapThis(info)->getTracker()->update(image, rect);
}
catch (std::exception &e) {
return tryCatch.throwError(e.what());
}

if (ret) {
info.GetReturnValue().Set(Rect::Converter::wrap(rect));
} else {
info.GetReturnValue().Set(Nan::Null());
}
}

NAN_METHOD(TrackerGOTURN::GetModel) {
// TBD
}

#endif

NAN_MODULE_INIT(TrackerGOTURN::Init) {
v8::Local<v8::FunctionTemplate> ctor = Nan::New<v8::FunctionTemplate>(TrackerGOTURN::New);
v8::Local<v8::ObjectTemplate> instanceTemplate = ctor->InstanceTemplate();

#if CV_VERSION_GREATER_EQUAL(4, 5, 2)
Nan::SetPrototypeMethod(ctor, "clear", TrackerGOTURN::Clear);
Nan::SetPrototypeMethod(ctor, "init", TrackerGOTURN::Init);
Nan::SetPrototypeMethod(ctor, "update", TrackerGOTURN::Update);
Nan::SetPrototypeMethod(ctor, "getModel", TrackerGOTURN::GetModel);
#else
Tracker::Init(ctor);

#endif
constructor.Reset(ctor);
ctor->SetClassName(FF::newString("TrackerGOTURN"));
instanceTemplate->SetInternalFieldCount(1);
Expand Down
13 changes: 11 additions & 2 deletions cc/tracking/Trackers/TrackerGOTURN.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@
#ifndef __FF_TRACKERGOTURN_H__
#define __FF_TRACKERGOTURN_H__

#if CV_VERSION_GREATER_EQUAL(4, 5, 2)
class TrackerGOTURN : public FF::ObjectWrapBase<TrackerGOTURN>, public Nan::ObjectWrap {
#else
class TrackerGOTURN : public Tracker {
#endif
public:
cv::Ptr<cv::TrackerGOTURN> tracker;

static NAN_MODULE_INIT(Init);
static NAN_METHOD(New);

#if CV_VERSION_GREATER_EQUAL(4, 5, 2)
static NAN_METHOD(Clear);
static NAN_METHOD(Init);
static NAN_METHOD(Update);
static NAN_METHOD(GetModel);
#endif
static Nan::Persistent<v8::FunctionTemplate> constructor;

cv::Ptr<cv::Tracker> getTracker() {
Expand All @@ -21,4 +30,4 @@ class TrackerGOTURN : public Tracker {

#endif

#endif
#endif
Loading

0 comments on commit 91bc118

Please sign in to comment.