Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fig committed Sep 19, 2024
1 parent 903b0c9 commit 88d05bb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
15 changes: 12 additions & 3 deletions cc/tracking/Trackers/TrackerNano.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,23 @@ NAN_METHOD(TrackerNano::Init) {
FF::TryCatch tryCatch("TrackerNano::Init");
cv::Mat image;
cv::Rect2d boundingBox;
if (
Mat::Converter::arg(0, &image, info) || Rect::Converter::arg(1, &boundingBox, info)) {

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

TrackerNano::unwrapThis(info)->getTracker()->init(image, boundingBox);
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;
Expand Down
17 changes: 11 additions & 6 deletions test/tests/tracking/TrackerNano.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ 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 {
Expand All @@ -21,7 +28,7 @@ if (toTest.tracking) {

describe('constructor', () => {
it('can be constructed', () => {
const tracker = new cv.TrackerNano("./TrackerNanoModels/backbone.onnx", "./TrackerNanoModels/neckhead.onnx");
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');
});
Expand All @@ -30,11 +37,10 @@ if (toTest.tracking) {
describe('init', () => {
it('should throw if no args', () => {
// @ts-expect-error missing args
expect(() => new cv.TrackerNano().init()).to.throw('Tracker::Init - Error: expected argument 0 to be of type');
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 tracker = new cv.TrackerNano();
const ret = tracker.init(testImg, new cv.Rect(0, 0, 10, 10));
expect(ret).to.be.true;
});
Expand All @@ -43,16 +49,15 @@ if (toTest.tracking) {
describe('update', () => {
it('should throw if no args', () => {
// @ts-expect-error missing args
expect(() => new cv.TrackerNano().update()).to.throw('Tracker::Update - Error: expected argument 0 to be of type');
expect(() => tracker.update()).to.throw('TrackerNano::Update - Error: expected argument 0 to be of type');
});

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

});
}
}

0 comments on commit 88d05bb

Please sign in to comment.