Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.

Commit bf1c41f

Browse files
bugfixes and testcases for new HOG bindings
1 parent e681da0 commit bf1c41f

File tree

11 files changed

+262
-24
lines changed

11 files changed

+262
-24
lines changed

binding.gyp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"cc/modules/objdetect/objdetect.cc",
4848
"cc/modules/objdetect/CascadeClassifier.cc",
4949
"cc/modules/objdetect/HOGDescriptor.cc",
50+
"cc/modules/objdetect/DetectionROI.cc",
5051
"cc/modules/machinelearning/machinelearning.cc",
5152
"cc/modules/machinelearning/ParamGrid.cc",
5253
"cc/modules/machinelearning/StatModel.cc",

cc/AbstractConverter.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ class SingleTypeConverter {
2828
return ConverterType::unwrap(jsVal);
2929
}
3030

31+
static T* unwrapPtr(v8::Local<v8::Value> jsVal) {
32+
return ConverterType::unwrapPtr(jsVal);
33+
}
34+
3135
static v8::Local<v8::Value> wrap(T val) {
3236
return ConverterType::wrap(val);
3337
}
@@ -48,12 +52,16 @@ class AbstractConverter {
4852
return ConverterType::unwrap(jsVal);
4953
}
5054

55+
static T* unwrapPtr(v8::Local<v8::Value> jsVal) {
56+
return ConverterType::unwrapPtr(jsVal);
57+
}
58+
5159
static v8::Local<v8::Value> wrap(T val) {
5260
return ConverterType::wrap(val);
5361
}
5462

5563
static bool unwrap(T* val, v8::Local<v8::Value> jsVal) {
56-
return ConverterType::unwrap(vec, jsVal);
64+
return ConverterType::unwrap(val, jsVal);
5765
}
5866

5967
static bool optProp(T* val, const char* prop, v8::Local<v8::Object> opts) {

cc/InstanceConverter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ class InstanceConverterType {
1818
return Nan::ObjectWrap::Unwrap<Clazz>(jsVal->ToObject())->getNativeObject();
1919
}
2020

21+
static T* unwrapPtr(v8::Local<v8::Value> jsVal) {
22+
return Nan::ObjectWrap::Unwrap<Clazz>(jsVal->ToObject())->getNativeObjectPtr();
23+
}
24+
2125
static v8::Local<v8::Value> wrap(T val) {
2226
v8::Local<v8::Object> jsObj = Nan::NewInstance(Nan::New(Clazz::constructor)->GetFunction()).ToLocalChecked();
2327
*Nan::ObjectWrap::Unwrap<Clazz>(jsObj)->getNativeObjectPtr() = val;

cc/modules/objdetect/DetectionROI.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ class DetectionROI : public Nan::ObjectWrap {
2121

2222
static NAN_SETTER(locationsSet) {
2323
std::vector<cv::Point> locations;
24-
if (!ObjectArrayConverter<Point2, cv::Point2d, cv::Point>::unwrap(&locations, value)) {
24+
if (ObjectArrayConverter<Point2, cv::Point2d, cv::Point>::unwrap(&locations, value)) {
2525
return Nan::ThrowError("expected locations to be an Array of type Point2");
2626
}
27+
Converter::unwrapPtr(info.This())->locations = locations;
2728
}
2829

2930
static NAN_GETTER(confidencesGet) {
@@ -32,9 +33,10 @@ class DetectionROI : public Nan::ObjectWrap {
3233

3334
static NAN_SETTER(confidencesSet) {
3435
std::vector<double> confidences;
35-
if (!DoubleArrayConverter::unwrap(&confidences, value)) {
36+
if (DoubleArrayConverter::unwrap(&confidences, value)) {
3637
return Nan::ThrowError("expected confidences to be an Array of type Number");
3738
}
39+
Converter::unwrapPtr(info.This())->confidences = confidences;
3840
}
3941

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

cc/modules/objdetect/HOGDescriptor.cc

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ struct HOGDescriptor::DetectWorker : public SimpleWorker {
272272
DoubleConverter::optArg(1, &hitThreshold, info) ||
273273
Size::Converter::optArg(2, &winStride, info) ||
274274
Size::Converter::optArg(3, &padding, info) ||
275-
ObjectArrayConverter<Point, cv::Point2d, cv::Point>::optArg(4, &searchLocations, info)
275+
ObjectArrayConverter<Point2, cv::Point2d, cv::Point>::optArg(4, &searchLocations, info)
276276
);
277277
}
278278

@@ -286,7 +286,7 @@ struct HOGDescriptor::DetectWorker : public SimpleWorker {
286286
DoubleConverter::optProp(&hitThreshold, "hitThreshold", opts) ||
287287
Size::Converter::optProp(&winStride, "winStride", opts) ||
288288
Size::Converter::optProp(&padding, "padding", opts) ||
289-
ObjectArrayConverter<Point, cv::Point2d, cv::Point>::optProp(&searchLocations, "searchLocations", opts)
289+
ObjectArrayConverter<Point2, cv::Point2d, cv::Point>::optProp(&searchLocations, "searchLocations", opts)
290290
);
291291
}
292292
};
@@ -326,16 +326,16 @@ struct HOGDescriptor::DetectROIWorker : public SimpleWorker {
326326

327327
v8::Local<v8::Value> getReturnValue() {
328328
v8::Local<v8::Object> ret = Nan::New<v8::Object>();
329-
Nan::Set(ret, Nan::New("foundLocations").ToLocalChecked(), ObjectArrayConverter<Point, cv::Point2d, cv::Point>::wrap(foundLocations));
329+
Nan::Set(ret, Nan::New("foundLocations").ToLocalChecked(), ObjectArrayConverter<Point2, cv::Point2d, cv::Point>::wrap(foundLocations));
330330
Nan::Set(ret, Nan::New("confidences").ToLocalChecked(), DoubleArrayConverter::wrap(confidences));
331331
return ret;
332332
}
333333

334334
bool unwrapRequiredArgs(Nan::NAN_METHOD_ARGS_TYPE info) {
335335
return (
336336
Mat::Converter::arg(0, &img, info) ||
337-
ObjectArrayConverter<Point, cv::Point2d, cv::Point>::arg(1, &locations, info)
338-
);
337+
ObjectArrayConverter<Point2, cv::Point2d, cv::Point>::arg(1, &locations, info)
338+
);
339339
}
340340

341341
bool unwrapOptionalArgs(Nan::NAN_METHOD_ARGS_TYPE info) {
@@ -356,7 +356,7 @@ struct HOGDescriptor::DetectROIWorker : public SimpleWorker {
356356
DoubleConverter::optProp(&hitThreshold, "hitThreshold", opts) ||
357357
Size::Converter::optProp(&winStride, "winStride", opts) ||
358358
Size::Converter::optProp(&padding, "padding", opts)
359-
);
359+
);
360360
}
361361
};
362362

@@ -572,11 +572,10 @@ NAN_METHOD(HOGDescriptor::CheckDetectorSize) {
572572
NAN_METHOD(HOGDescriptor::SetSVMDetector) {
573573
FF_METHOD_CONTEXT("SetSVMDetector");
574574
std::vector<float> detector;
575-
if (!FF_HAS_ARG(0) || !FloatArrayConverter::unwrap(&detector, info[0])) {
575+
if (!FF_HAS_ARG(0) || FloatArrayConverter::unwrap(&detector, info[0])) {
576576
FF_THROW("expected detector to be an Array of type Number");
577577
}
578-
579-
HOGDescriptor::Converter::unwrap(info.This()).setSVMDetector(detector);
578+
HOGDescriptor::Converter::unwrapPtr(info.This())->setSVMDetector(detector);
580579
}
581580

582581
NAN_METHOD(HOGDescriptor::Save) {

cc/modules/objdetect/objdetect.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#include "objdetect.h"
22
#include "CascadeClassifier.h"
33
#include "HOGDescriptor.h"
4+
#include "DetectionROI.h"
45

56
NAN_MODULE_INIT(Objdetect::Init) {
67
CascadeClassifier::Init(target);
78
HOGDescriptor::Init(target);
9+
DetectionROI::Init(target);
810
};

data/people.jpeg

89.3 KB
Loading

test/tests/modules/objdetect/DetectionROITests.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ module.exports = () => {
2020
expect(detectionROI).to.have.property('locations')
2121
.to.be.an('array')
2222
.lengthOf(3)
23-
.to.have.ordered.members(params.locations);
23+
.to.deep.equal(params.locations);
2424
expect(detectionROI).to.have.property('confidences')
2525
.to.be.an('array')
2626
.lengthOf(3)
27-
.to.have.ordered.members(params.confidences);
27+
.to.deep.equal(params.confidences);
2828
});
2929
});
3030
};

0 commit comments

Comments
 (0)