Skip to content

Commit

Permalink
Merge pull request #165 from figamore/NanoTrack-Implementation
Browse files Browse the repository at this point in the history
TrackerNano implementation
  • Loading branch information
UrielCh authored Sep 26, 2024
2 parents e1412d0 + 3e3f4af commit c1b0fc8
Show file tree
Hide file tree
Showing 14 changed files with 6,478 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![NPM Version](https://img.shields.io/npm/v/@u4/opencv4nodejs.svg?style=flat)](https://www.npmjs.org/package/@u4/opencv4nodejs)

## Getting starts
## Getting started

Opencv4nodejs can be linked to a prebuild openCV 3 or 4. or can build its own openCV using [@u4/opencv-build](https://www.npmjs.com/package/@u4/opencv-build),
In this case, you have to choose which version you want to link.
Expand Down
1 change: 1 addition & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"cc/tracking/Trackers/TrackerMedianFlow.cc",
"cc/tracking/Trackers/TrackerTLD.cc",
"cc/tracking/Trackers/TrackerGOTURN.cc",
"cc/tracking/Trackers/TrackerNano.cc",
"cc/tracking/Trackers/TrackerCSRT.cc",
"cc/tracking/Trackers/TrackerCSRTParams.cc",
"cc/tracking/Trackers/TrackerMOSSE.cc",
Expand Down
1 change: 1 addition & 0 deletions binding_old.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"cc/tracking/Trackers/TrackerMedianFlow.cc",
"cc/tracking/Trackers/TrackerTLD.cc",
"cc/tracking/Trackers/TrackerGOTURN.cc",
"cc/tracking/Trackers/TrackerNano.cc",
"cc/tracking/Trackers/TrackerCSRT.cc",
"cc/tracking/Trackers/TrackerCSRTParams.cc",
"cc/tracking/Trackers/TrackerMOSSE.cc",
Expand Down
108 changes: 108 additions & 0 deletions cc/tracking/Trackers/TrackerNano.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#include "opencv_modules.h"

#ifdef HAVE_OPENCV_TRACKING

#include "TrackerNano.h"

// Ensure that this code is only compiled if OpenCV is 4.7.0 or greater
#if CV_VERSION_GREATER_EQUAL(4, 7, 0)

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

NAN_METHOD(TrackerNano::Init) {
FF::TryCatch tryCatch("TrackerNano::Init");
cv::Mat image;
cv::Rect2d boundingBox;

// Check if the arguments are correctly passed
if (Mat::Converter::arg(0, &image, info) || Rect::Converter::arg(1, &boundingBox, info)) {
return tryCatch.reThrow();
}

try {
TrackerNano::unwrapThis(info)->getTracker()->init(image, boundingBox);

// If no error is thrown, return true
info.GetReturnValue().Set(Nan::True());
} catch (const std::exception& e) {
return tryCatch.throwError(e.what());
}
}


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

cv::Rect rect;
bool ret = false;

try {
ret = TrackerNano::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_MODULE_INIT(TrackerNano::Init) {
v8::Local<v8::FunctionTemplate> ctor = Nan::New<v8::FunctionTemplate>(TrackerNano::New);
v8::Local<v8::ObjectTemplate> instanceTemplate = ctor->InstanceTemplate();

Nan::SetPrototypeMethod(ctor, "init", TrackerNano::Init);
Nan::SetPrototypeMethod(ctor, "update", TrackerNano::Update);

constructor.Reset(ctor);
ctor->SetClassName(FF::newString("TrackerNano"));
instanceTemplate->SetInternalFieldCount(1);

Nan::Set(target, FF::newString("TrackerNano"), FF::getFunction(ctor));
};

NAN_METHOD(TrackerNano::New) {
FF::TryCatch tryCatch("TrackerNano::New");
FF_ASSERT_CONSTRUCT_CALL();

// Default model paths
std::string backboneModelPath = "backbone.onnx";
std::string neckheadModelPath = "neckhead.onnx";

// Check if the user passed model paths as arguments
if (info.Length() > 0) {
if (FF::StringConverter::arg(0, &backboneModelPath, info)) {
return tryCatch.reThrow();
}
}

if (info.Length() > 1) {
if (FF::StringConverter::arg(1, &neckheadModelPath, info)) {
return tryCatch.reThrow();
}
}

// Initialize TrackerNano with provided or default models
TrackerNano* self = new TrackerNano();

// Create tracker with provided ONNX models
cv::TrackerNano::Params params;
params.backbone = backboneModelPath;
params.neckhead = neckheadModelPath;

// Create the tracker instance with these parameters
self->tracker = cv::TrackerNano::create(params);

self->Wrap(info.Holder());
info.GetReturnValue().Set(info.Holder());
}

#endif

#endif
29 changes: 29 additions & 0 deletions cc/tracking/Trackers/TrackerNano.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "../Tracker.h"

#if CV_VERSION_GREATER_EQUAL(4, 7, 0)

#ifndef __FF_TRACKERNANO_H__
#define __FF_TRACKERNANO_H__

// Ensure that TrackerNano is only defined for OpenCV 4.7.0 or greater
#if CV_VERSION_GREATER_EQUAL(4, 7, 0)
class TrackerNano : public FF::ObjectWrapBase<TrackerNano>, public Nan::ObjectWrap {
public:
cv::Ptr<cv::TrackerNano> tracker;

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

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

cv::Ptr<cv::Tracker> getTracker() {
return tracker;
}
};
#endif

#endif

#endif
8 changes: 8 additions & 0 deletions cc/tracking/tracking.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
#include "./Trackers/TrackerCSRT.h"
#endif

#if CV_VERSION_GREATER_EQUAL(4, 7, 0)
#include "./Trackers/TrackerNano.h"
#endif

NAN_MODULE_INIT(Tracking::Init) {
TrackerBoosting::Init(target);
TrackerMedianFlow::Init(target);
Expand All @@ -50,6 +54,10 @@ NAN_MODULE_INIT(Tracking::Init) {
#if CV_VERSION_GREATER_EQUAL(3, 4, 1)
TrackerCSRT::Init(target);
#endif

#if CV_VERSION_GREATER_EQUAL(4, 7 , 0)
TrackerNano::Init(target);
#endif
};

#endif
5 changes: 3 additions & 2 deletions cjs/lib/opencv4nodejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ exports.goodFeaturesToTrack = exports.cannyAsync = exports.canny = exports.apply
exports.CAP_PROP_ISO_SPEED = exports.CAP_PROP_GUID = exports.CAP_PROP_FOCUS = exports.CAP_PROP_ZOOM = exports.CAP_PROP_WHITE_BALANCE_RED_V = exports.CAP_PROP_TRIGGER_DELAY = exports.CAP_PROP_TRIGGER = exports.CAP_PROP_TEMPERATURE = exports.CAP_PROP_GAMMA = exports.CAP_PROP_AUTO_EXPOSURE = exports.CAP_PROP_SHARPNESS = exports.CAP_PROP_MONOCHROME = exports.CAP_PROP_RECTIFICATION = exports.CAP_PROP_WHITE_BALANCE_BLUE_U = exports.CAP_PROP_CONVERT_RGB = exports.CAP_PROP_EXPOSURE = exports.CAP_PROP_GAIN = exports.CAP_PROP_HUE = exports.CAP_PROP_SATURATION = exports.CAP_PROP_CONTRAST = exports.CAP_PROP_BRIGHTNESS = exports.CAP_PROP_MODE = exports.CAP_PROP_FORMAT = exports.CAP_PROP_FRAME_COUNT = exports.CAP_PROP_FOURCC = exports.CAP_PROP_FPS = exports.CAP_PROP_FRAME_HEIGHT = exports.CAP_PROP_FRAME_WIDTH = exports.CAP_PROP_POS_AVI_RATIO = exports.CAP_PROP_POS_FRAMES = exports.CAP_PROP_POS_MSEC = exports.Contour = exports.Moments = exports.calcHistAsync = exports.calcHist = exports.accumulateWeightedAsync = exports.accumulateWeighted = exports.accumulateSquareAsync = exports.accumulateSquare = exports.accumulateProductAsync = exports.accumulateProduct = exports.accumulateAsync = exports.accumulate = exports.medianBlurAsync = exports.medianBlur = exports.gaussianBlurAsync = exports.gaussianBlur = exports.blurAsync = exports.blur = exports.goodFeaturesToTrackAsync = void 0;
exports.destroyWindow = exports.imdecode = exports.imencode = exports.waitKeyEx = exports.waitKey = exports.imwrite = exports.imshowWait = exports.imshow = exports.imread = exports.VideoWriter = exports.VideoCapture = exports.VIDEOWRITER_PROP_NSTRIPES = exports.VIDEOWRITER_PROP_FRAMEBYTES = exports.VIDEOWRITER_PROP_QUALITY = exports.CAP_ARAVIS = exports.CAP_IMAGES = exports.CAP_FFMPEG = exports.CAP_GSTREAMER = exports.CAP_GPHOTO2 = exports.CAP_OPENNI2_ASUS = exports.CAP_OPENNI2 = exports.CAP_INTELPERC = exports.CAP_WINRT = exports.CAP_MSMF = exports.CAP_GIGANETIX = exports.CAP_AVFOUNDATION = exports.CAP_XIAPI = exports.CAP_ANDROID = exports.CAP_OPENNI_ASUS = exports.CAP_OPENNI = exports.CAP_PVAPI = exports.CAP_DSHOW = exports.CAP_UNICAP = exports.CAP_QT = exports.CAP_CMU1394 = exports.CAP_DC1394 = exports.CAP_IEEE1394 = exports.CAP_FIREWIRE = exports.CAP_V4L2 = exports.CAP_V4L = exports.CAP_VFW = exports.CAP_ANY = exports.CAP_PROP_AUTOFOCUS = exports.CAP_PROP_BUFFERSIZE = exports.CAP_PROP_SETTINGS = exports.CAP_PROP_IRIS = exports.CAP_PROP_ROLL = exports.CAP_PROP_TILT = exports.CAP_PROP_PAN = exports.CAP_PROP_BACKLIGHT = void 0;
exports.HOGHistogramNormType = exports.HOGDescriptor = exports.CascadeClassifier = exports.SVM = exports.StatModel = exports.ParamGrid = exports.TrainData = exports.statModel = exports.ml = exports.IMWRITE_PNG_STRATEGY_FIXED = exports.IMWRITE_PNG_STRATEGY_RLE = exports.IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY = exports.IMWRITE_PNG_STRATEGY_FILTERED = exports.IMWRITE_PNG_STRATEGY_DEFAULT = exports.IMWRITE_PAM_FORMAT_RGB_ALPHA = exports.IMWRITE_PAM_FORMAT_RGB = exports.IMWRITE_PAM_FORMAT_GRAYSCALE_ALPHA = exports.IMWRITE_PAM_FORMAT_GRAYSCALE = exports.IMWRITE_PAM_FORMAT_BLACKANDWHITE = exports.IMWRITE_PAM_FORMAT_NULL = exports.IMWRITE_PAM_TUPLETYPE = exports.IMREAD_IGNORE_ORIENTATION = exports.IMREAD_REDUCED_COLOR_8 = exports.IMREAD_REDUCED_GRAYSCALE_8 = exports.IMREAD_REDUCED_COLOR_4 = exports.IMREAD_REDUCED_GRAYSCALE_4 = exports.IMREAD_REDUCED_COLOR_2 = exports.IMREAD_REDUCED_GRAYSCALE_2 = exports.IMWRITE_WEBP_QUALITY = exports.IMWRITE_PXM_BINARY = exports.IMWRITE_PNG_BILEVEL = exports.IMWRITE_PNG_STRATEGY = exports.IMWRITE_PNG_COMPRESSION = exports.IMWRITE_JPEG_CHROMA_QUALITY = exports.IMWRITE_JPEG_LUMA_QUALITY = exports.IMWRITE_JPEG_RST_INTERVAL = exports.IMWRITE_JPEG_OPTIMIZE = exports.IMWRITE_JPEG_PROGRESSIVE = exports.IMWRITE_JPEG_QUALITY = exports.IMREAD_LOAD_GDAL = exports.IMREAD_ANYCOLOR = exports.IMREAD_ANYDEPTH = exports.IMREAD_COLOR = exports.IMREAD_GRAYSCALE = exports.IMREAD_UNCHANGED = exports.imdecodeAsync = exports.imencodeAsync = exports.imwriteAsync = exports.imreadAsync = exports.destroyAllWindows = void 0;
exports.HAAR_FRONTALFACE_ALT2 = exports.HAAR_FRONTALFACE_ALT = exports.HAAR_FRONTALCATFACE_EXTENDED = exports.HAAR_FRONTALCATFACE = exports.HAAR_EYE_TREE_EYEGLASSES = exports.HAAR_EYE = exports.PHash = exports.SLICO = exports.SLIC = exports.SuperpixelLSC = exports.SuperpixelSLIC = exports.SuperpixelSEEDS = exports.SURFDetector = exports.SIFTDetector = exports.BackgroundSubtractorKNN = exports.BackgroundSubtractorMOG2 = exports.TrackerCSRT = exports.TrackerCSRTParams = exports.TrackerMOSSE = exports.TrackerGOTURN = exports.trackerKCFModes = exports.MultiTracker = exports.TrackerKCF = exports.TrackerKCFParams = exports.TrackerTLD = exports.TrackerMIL = exports.TrackerMILParams = exports.TrackerMedianFlow = exports.TrackerBoosting = exports.TrackerBoostingParams = exports.createOCRHMMTransitionsTableAsync = exports.createOCRHMMTransitionsTable = exports.loadOCRHMMClassifierCNNAsync = exports.loadOCRHMMClassifierCNN = exports.loadOCRHMMClassifierNMAsync = exports.loadOCRHMMClassifierNM = exports.OCRHMMClassifier = exports.OCRHMMDecoder = exports.seamlessCloneAsync = exports.seamlessClone = exports.inpaintAsync = exports.inpaint = exports.fastNlMeansDenoisingColoredAsync = exports.fastNlMeansDenoisingColored = exports.MONOCHROME_TRANSFER = exports.MIXED_CLONE = exports.NORMAL_CLONE = exports.INPAINT_TELEA = exports.INPAINT_NS = exports.DetectionROI = void 0;
exports.HAAR_FRONTALFACE_ALT2 = exports.HAAR_FRONTALFACE_ALT = exports.HAAR_FRONTALCATFACE_EXTENDED = exports.HAAR_FRONTALCATFACE = exports.HAAR_EYE_TREE_EYEGLASSES = exports.HAAR_EYE = exports.PHash = exports.SLICO = exports.SLIC = exports.SuperpixelLSC = exports.SuperpixelSLIC = exports.SuperpixelSEEDS = exports.SURFDetector = exports.SIFTDetector = exports.BackgroundSubtractorKNN = exports.BackgroundSubtractorMOG2 = exports.TrackerCSRT = exports.TrackerCSRTParams = exports.TrackerMOSSE = exports.TrackerGOTURN = exports.TrackerNano = exports.trackerKCFModes = exports.MultiTracker = exports.TrackerKCF = exports.TrackerKCFParams = exports.TrackerTLD = exports.TrackerMIL = exports.TrackerMILParams = exports.TrackerMedianFlow = exports.TrackerBoosting = exports.TrackerBoostingParams = exports.createOCRHMMTransitionsTableAsync = exports.createOCRHMMTransitionsTable = exports.loadOCRHMMClassifierCNNAsync = exports.loadOCRHMMClassifierCNN = exports.loadOCRHMMClassifierNMAsync = exports.loadOCRHMMClassifierNM = exports.OCRHMMClassifier = exports.OCRHMMDecoder = exports.seamlessCloneAsync = exports.seamlessClone = exports.inpaintAsync = exports.inpaint = exports.fastNlMeansDenoisingColoredAsync = exports.fastNlMeansDenoisingColored = exports.MONOCHROME_TRANSFER = exports.MIXED_CLONE = exports.NORMAL_CLONE = exports.INPAINT_TELEA = exports.INPAINT_NS = exports.DetectionROI = void 0;
exports.ORB = exports.FAST = exports.KAZE = exports.AKAZE = exports.AGAST = exports.dropOverlappingZone = exports.getScoreMax = exports.toMatTypeName = exports.getVersionString = exports.getVersion = exports.drawDetection = exports.drawTextBox = exports.LBP_SILVERWARE = exports.LBP_PROFILEFACE = exports.LBP_FRONTALFACE_IMPROVED = exports.LBP_FRONTALFACE = exports.LBP_FRONTALCATFACE = exports.HAAR_UPPERBODY = exports.HAAR_SMILE = exports.HAAR_RUSSIAN_PLATE_NUMBER = exports.HAAR_RIGHTEYE_2SPLITS = exports.HAAR_PROFILEFACE = exports.HAAR_LOWERBODY = exports.HAAR_LICENCE_PLATE_RUS_16STAGES = exports.HAAR_LEFTEYE_2SPLITS = exports.HAAR_FULLBODY = exports.HAAR_FRONTALFACE_DEFAULT = exports.HAAR_FRONTALFACE_ALT_TREE = void 0;
const node_path_1 = __importDefault(require("node:path"));
const promisify_js_1 = __importDefault(require("./promisify.js"));
Expand Down Expand Up @@ -998,7 +998,7 @@ exports.createOCRHMMTransitionsTableAsync = createOCRHMMTransitionsTableAsync;
exports.TrackerBoostingParams = TrackerBoostingParams;
exports.TrackerBoosting = TrackerBoosting;
exports.TrackerMedianFlow = TrackerMedianFlow;
const { TrackerMILParams, TrackerMIL, TrackerTLD, TrackerKCFParams, TrackerKCF, MultiTracker, trackerKCFModes, TrackerGOTURN, TrackerMOSSE, TrackerCSRTParams, TrackerCSRT, BackgroundSubtractorMOG2, BackgroundSubtractorKNN, SIFTDetector, SURFDetector } = exports.cv;
const { TrackerMILParams, TrackerMIL, TrackerTLD, TrackerKCFParams, TrackerKCF, MultiTracker, trackerKCFModes, TrackerGOTURN, TrackerNano, TrackerMOSSE, TrackerCSRTParams, TrackerCSRT, BackgroundSubtractorMOG2, BackgroundSubtractorKNN, SIFTDetector, SURFDetector } = exports.cv;
exports.TrackerMILParams = TrackerMILParams;
exports.TrackerMIL = TrackerMIL;
exports.TrackerTLD = TrackerTLD;
Expand All @@ -1007,6 +1007,7 @@ exports.TrackerKCF = TrackerKCF;
exports.MultiTracker = MultiTracker;
exports.trackerKCFModes = trackerKCFModes;
exports.TrackerGOTURN = TrackerGOTURN;
exports.TrackerNano = TrackerNano;
exports.TrackerMOSSE = TrackerMOSSE;
exports.TrackerCSRTParams = TrackerCSRTParams;
exports.TrackerCSRT = TrackerCSRT;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/opencv4nodejs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ const { TrainData,ParamGrid,StatModel,SVM,CascadeClassifier,HOGDescriptor,HOGHis
export { TrainData,ParamGrid,StatModel,SVM,CascadeClassifier,HOGDescriptor,HOGHistogramNormType,DetectionROI,INPAINT_NS,INPAINT_TELEA,NORMAL_CLONE,MIXED_CLONE,MONOCHROME_TRANSFER,fastNlMeansDenoisingColored,fastNlMeansDenoisingColoredAsync };
const { inpaint,inpaintAsync,seamlessClone,seamlessCloneAsync,OCRHMMDecoder,OCRHMMClassifier,loadOCRHMMClassifierNM,loadOCRHMMClassifierNMAsync,loadOCRHMMClassifierCNN,loadOCRHMMClassifierCNNAsync,createOCRHMMTransitionsTable,createOCRHMMTransitionsTableAsync,TrackerBoostingParams,TrackerBoosting,TrackerMedianFlow } = cv;
export { inpaint,inpaintAsync,seamlessClone,seamlessCloneAsync,OCRHMMDecoder,OCRHMMClassifier,loadOCRHMMClassifierNM,loadOCRHMMClassifierNMAsync,loadOCRHMMClassifierCNN,loadOCRHMMClassifierCNNAsync,createOCRHMMTransitionsTable,createOCRHMMTransitionsTableAsync,TrackerBoostingParams,TrackerBoosting,TrackerMedianFlow };
const { TrackerMILParams,TrackerMIL,TrackerTLD,TrackerKCFParams,TrackerKCF,MultiTracker,trackerKCFModes,TrackerGOTURN,TrackerMOSSE,TrackerCSRTParams,TrackerCSRT,BackgroundSubtractorMOG2,BackgroundSubtractorKNN,SIFTDetector,SURFDetector } = cv;
export { TrackerMILParams,TrackerMIL,TrackerTLD,TrackerKCFParams,TrackerKCF,MultiTracker,trackerKCFModes,TrackerGOTURN,TrackerMOSSE,TrackerCSRTParams,TrackerCSRT,BackgroundSubtractorMOG2,BackgroundSubtractorKNN,SIFTDetector,SURFDetector };
const { TrackerMILParams,TrackerMIL,TrackerTLD,TrackerKCFParams,TrackerKCF,MultiTracker,trackerKCFModes,TrackerGOTURN,TrackerNano,TrackerMOSSE,TrackerCSRTParams,TrackerCSRT,BackgroundSubtractorMOG2,BackgroundSubtractorKNN,SIFTDetector,SURFDetector } = cv;
export { TrackerMILParams,TrackerMIL,TrackerTLD,TrackerKCFParams,TrackerKCF,MultiTracker,trackerKCFModes,TrackerGOTURN,TrackerNano,TrackerMOSSE,TrackerCSRTParams,TrackerCSRT,BackgroundSubtractorMOG2,BackgroundSubtractorKNN,SIFTDetector,SURFDetector };
const { SuperpixelSEEDS,SuperpixelSLIC,SuperpixelLSC,SLIC,SLICO,PHash,HAAR_EYE,HAAR_EYE_TREE_EYEGLASSES,HAAR_FRONTALCATFACE,HAAR_FRONTALCATFACE_EXTENDED,HAAR_FRONTALFACE_ALT,HAAR_FRONTALFACE_ALT2,HAAR_FRONTALFACE_ALT_TREE,HAAR_FRONTALFACE_DEFAULT,HAAR_FULLBODY } = cv;
export { SuperpixelSEEDS,SuperpixelSLIC,SuperpixelLSC,SLIC,SLICO,PHash,HAAR_EYE,HAAR_EYE_TREE_EYEGLASSES,HAAR_FRONTALCATFACE,HAAR_FRONTALCATFACE_EXTENDED,HAAR_FRONTALFACE_ALT,HAAR_FRONTALFACE_ALT2,HAAR_FRONTALFACE_ALT_TREE,HAAR_FRONTALFACE_DEFAULT,HAAR_FULLBODY };
const { HAAR_LEFTEYE_2SPLITS,HAAR_LICENCE_PLATE_RUS_16STAGES,HAAR_LOWERBODY,HAAR_PROFILEFACE,HAAR_RIGHTEYE_2SPLITS,HAAR_RUSSIAN_PLATE_NUMBER,HAAR_SMILE,HAAR_UPPERBODY,LBP_FRONTALCATFACE,LBP_FRONTALFACE,LBP_FRONTALFACE_IMPROVED,LBP_PROFILEFACE,LBP_SILVERWARE,drawTextBox,drawDetection } = cv;
Expand Down
63 changes: 63 additions & 0 deletions test/tests/tracking/TrackerNano.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { expect } from 'chai';
import { Mat, TrackerNano } from '../../../typings';
import { getTestContext } from '../model';
import toTest from '../toTest';
import path from 'path'; // Import path module to handle file paths
import { fileURLToPath } from 'url';

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const backbonePath = path.join(__dirname, '/TrackerNanoModels/backbone.onnx');
const neckheadPath = path.join(__dirname, '/TrackerNanoModels/neckhead.onnx');
let tracker: TrackerNano

if (toTest.tracking) {
const {
cv,
cvVersionGreaterEqual,
getTestImg,
} = getTestContext();

const hasNano = cvVersionGreaterEqual(4, 7, 0);

(hasNano ? describe : describe.skip)('TrackerNano', () => {
let testImg: Mat;

before(() => {
testImg = getTestImg();
});

describe('constructor', () => {
it('can be constructed', () => {
tracker = new cv.TrackerNano(backbonePath, neckheadPath);
expect(tracker).to.have.property('init').to.be.a('function');
expect(tracker).to.have.property('update').to.be.a('function');
});
});

describe('init', () => {
it('should throw if no args', () => {
// @ts-expect-error missing args
expect(() => tracker.init()).to.throw('TrackerNano::Init - Error: expected argument 0 to be of type');
});

it('can be called with frame and initial box', () => {
const ret = tracker.init(testImg, new cv.Rect(0, 0, 10, 10));
expect(ret).to.be.true;
});
});

describe('update', () => {
it('should throw if no args', () => {
// @ts-expect-error missing args
expect(() => tracker.update()).to.throw('TrackerNano::Update - Error: expected argument 0 to be of type');
});

it('returns bounding box', () => {
tracker.init(testImg, new cv.Rect(0, 0, 10, 10));
const rect = tracker.update(testImg);
expect(rect).to.be.instanceOf(cv.Rect);
});
});

});
}
Loading

0 comments on commit c1b0fc8

Please sign in to comment.