Skip to content
This repository was archived by the owner on Jul 1, 2024. It is now read-only.

Commit eded51f

Browse files
Update tests
1 parent 8c679ce commit eded51f

File tree

3 files changed

+48
-44
lines changed

3 files changed

+48
-44
lines changed

cppsrc/detector.cpp

+9-8
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ Value Detector::detectImagePath(const CallbackInfo &info) {
7474
float heir = info[2].ToNumber();
7575
float nms = info[3].ToNumber();
7676

77-
char *imageLocation = const_cast<char *>(
78-
static_cast<std::string>(info[0].As<String>()).c_str());
77+
std::string location = info[0].As<String>();
78+
79+
char* imageLocation = const_cast<char *>(location.c_str());
7980

8081
image loadedImage = load_image_color(imageLocation, 0, 0);
8182

@@ -140,15 +141,15 @@ Array Detector::detectImageInternal(Napi::Env env, image image, float thresh,
140141
for (int j = 0; j < this->classes; j++) {
141142
if (prob[j] > 0) {
142143

143-
Object bbox = Object::New(env);
144+
Object box = Object::New(env);
144145

145-
bbox.Set("w", Number::New(env, a.bbox.w));
146-
bbox.Set("h", Number::New(env, a.bbox.h));
147-
bbox.Set("x", Number::New(env, a.bbox.x));
148-
bbox.Set("y", Number::New(env, a.bbox.y));
146+
box.Set("w", Number::New(env, a.bbox.w));
147+
box.Set("h", Number::New(env, a.bbox.h));
148+
box.Set("x", Number::New(env, a.bbox.x));
149+
box.Set("y", Number::New(env, a.bbox.y));
149150

150151
Object detected = Object::New(env);
151-
detected.Set("bbox", bbox);
152+
detected.Set("box", box);
152153
detected.Set("prob", Number::New(env, prob[j]));
153154
detected.Set("name", String::New(env, this->names[j]));
154155

lib/darknet.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export class Darknet {
7171
);
7272
}
7373

74-
detect(path: string, config?: IConfig): Detection[] {
74+
detect(path: string, config: IConfig = {}): Detection[] {
7575
const thresh = (config.thresh !== undefined) ? config.thresh : 0.5;
7676
const hier = (config.hier_thresh !== undefined) ? config.hier_thresh : 0.5;
7777
const nms = (config.nms !== undefined) ? config.nms : 0.5;

spec/darknet.spec.js

+38-35
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { Darknet, DarknetExperimental } = require('../darknet');
1+
const { Darknet } = require('../darknet');
22
const path = require('path');
33

44
const config = {
@@ -90,48 +90,51 @@ describe('darknet', () => {
9090

9191
it('detects various images', () => {
9292
darknet = new Darknet(config);
93+
9394
const dog = darknet.detect(image('dog.jpg'));
94-
expect(JSON.stringify(dog)).toBe(JSON.stringify(DOG_RESULT));
95+
expect(dog).toEqual(DOG_RESULT);
96+
9597
const eagle = darknet.detect(image('eagle.jpg'));
96-
expect(JSON.stringify(eagle)).toBe(JSON.stringify(EAGLE_RESULT));
98+
expect(eagle).toEqual(EAGLE_RESULT);
99+
97100
const giraffe = darknet.detect(image('giraffe.jpg'));
98-
expect(JSON.stringify(giraffe)).toBe(JSON.stringify(GIRAFFE_RESULT));
101+
expect(giraffe).toEqual(GIRAFFE_RESULT);
99102
});
100103

101-
it('detects various images async (concurrent)', async () => {
102-
darknet_a = new Darknet(config);
103-
darknet_b = new Darknet(config);
104-
darknet_c = new Darknet(config);
105-
106-
return Promise.all([
107-
darknet_a.detectAsync(image('dog.jpg')),
108-
darknet_b.detectAsync(image('eagle.jpg')),
109-
darknet_c.detectAsync(image('giraffe.jpg'))
110-
]).then(values => {
111-
expect(JSON.stringify(values[0])).toBe(JSON.stringify(DOG_RESULT));
112-
expect(JSON.stringify(values[1])).toBe(JSON.stringify(EAGLE_RESULT));
113-
expect(JSON.stringify(values[2])).toBe(JSON.stringify(GIRAFFE_RESULT));
114-
});
115-
});
104+
// xit('detects various images async (concurrent)', async () => {
105+
// darknet_a = new Darknet(config);
106+
// darknet_b = new Darknet(config);
107+
// darknet_c = new Darknet(config);
108+
109+
// return Promise.all([
110+
// darknet_a.detectAsync(image('dog.jpg')),
111+
// darknet_b.detectAsync(image('eagle.jpg')),
112+
// darknet_c.detectAsync(image('giraffe.jpg'))
113+
// ]).then(values => {
114+
// expect(JSON.stringify(values[0])).toBe(JSON.stringify(DOG_RESULT));
115+
// expect(JSON.stringify(values[1])).toBe(JSON.stringify(EAGLE_RESULT));
116+
// expect(JSON.stringify(values[2])).toBe(JSON.stringify(GIRAFFE_RESULT));
117+
// });
118+
// });
119+
120+
// describe('experimental', () => {
121+
// xit('detects images async', async () => {
122+
// darknet = new DarknetExperimental(config);
123+
// return Promise.all([
124+
// darknet.detectAsync(image('dog.jpg')),
125+
// darknet.detectAsync(image('eagle.jpg')),
126+
// darknet.detectAsync(image('giraffe.jpg'))
127+
// ]).then(values => {
128+
// expect(JSON.stringify(values[0])).toBe(JSON.stringify(DOG_RESULT));
129+
// expect(JSON.stringify(values[1])).toBe(JSON.stringify(EAGLE_RESULT));
130+
// expect(JSON.stringify(values[2])).toBe(JSON.stringify(GIRAFFE_RESULT));
131+
// });
132+
// });
116133

117-
describe('experimental', () => {
118-
it('detects images async', async () => {
119-
darknet = new DarknetExperimental(config);
120-
return Promise.all([
121-
darknet.detectAsync(image('dog.jpg')),
122-
darknet.detectAsync(image('eagle.jpg')),
123-
darknet.detectAsync(image('giraffe.jpg'))
124-
]).then(values => {
125-
expect(JSON.stringify(values[0])).toBe(JSON.stringify(DOG_RESULT));
126-
expect(JSON.stringify(values[1])).toBe(JSON.stringify(EAGLE_RESULT));
127-
expect(JSON.stringify(values[2])).toBe(JSON.stringify(GIRAFFE_RESULT));
128-
});
129-
});
130-
131-
})
134+
// })
132135

133136
});
134137

135138
function image(location) {
136139
return path.resolve(__dirname + '/../examples/' + location);
137-
}
140+
}

0 commit comments

Comments
 (0)