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

Commit c3f8e3d

Browse files
Merge branch 'master' of https://github.com/justadudewhohacks/opencv4nodejs into #57fixes
2 parents 4c83e37 + a862a4c commit c3f8e3d

17 files changed

+1005
-10
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ ci/coverage-report
88
!cc
99
!data/got.jpg
1010
!data/Lenna.png
11+
!data/people.jpeg
1112
!data/traffic.mp4
1213
!data/text-models

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: 12 additions & 0 deletions
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,10 +52,18 @@ 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

63+
static bool unwrap(T* val, v8::Local<v8::Value> jsVal) {
64+
return ConverterType::unwrap(val, jsVal);
65+
}
66+
5567
static bool optProp(T* val, const char* prop, v8::Local<v8::Object> opts) {
5668
Nan::TryCatch tryCatch;
5769
if (

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.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include "DetectionROI.h"
2+
3+
Nan::Persistent<v8::FunctionTemplate> DetectionROI::constructor;
4+
5+
NAN_MODULE_INIT(DetectionROI::Init) {
6+
v8::Local<v8::FunctionTemplate> ctor = Nan::New<v8::FunctionTemplate>(DetectionROI::New);
7+
v8::Local<v8::ObjectTemplate> instanceTemplate = ctor->InstanceTemplate();
8+
9+
constructor.Reset(ctor);
10+
ctor->SetClassName(FF_NEW_STRING("DetectionROI"));
11+
instanceTemplate->SetInternalFieldCount(1);
12+
13+
Nan::SetAccessor(instanceTemplate, FF_NEW_STRING("scale"), scaleGet, scaleSet);
14+
Nan::SetAccessor(instanceTemplate, FF_NEW_STRING("locations"), locationsGet, locationsSet);
15+
Nan::SetAccessor(instanceTemplate, FF_NEW_STRING("confidences"), confidencesGet, confidencesSet);
16+
17+
target->Set(FF_NEW_STRING("DetectionROI"), ctor->GetFunction());
18+
};
19+
20+
NAN_METHOD(DetectionROI::New) {
21+
DetectionROI* self = new DetectionROI();
22+
self->Wrap(info.Holder());
23+
FF_RETURN(info.Holder());
24+
};

cc/modules/objdetect/DetectionROI.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include "Converters.h"
2+
#include <opencv2/objdetect.hpp>
3+
#include "Point.h"
4+
5+
#ifndef __FF_DETECTIONROI_H__
6+
#define __FF_DETECTIONROI_H__
7+
8+
class DetectionROI : public Nan::ObjectWrap {
9+
public:
10+
cv::DetectionROI detectionROI;
11+
12+
static NAN_MODULE_INIT(Init);
13+
static NAN_METHOD(New);
14+
15+
static FF_GETTER(DetectionROI, scaleGet, detectionROI.scale);
16+
static FF_SETTER_NUMBER(DetectionROI, scale, detectionROI.scale);
17+
static NAN_GETTER(locationsGet) {
18+
FF_VAL val = ObjectArrayConverter<Point2, cv::Point2d, cv::Point>::wrap(Converter::unwrap(info.This()).locations);
19+
FF_RETURN(val);
20+
}
21+
22+
static NAN_SETTER(locationsSet) {
23+
std::vector<cv::Point> locations;
24+
if (ObjectArrayConverter<Point2, cv::Point2d, cv::Point>::unwrap(&locations, value)) {
25+
return Nan::ThrowError("expected locations to be an Array of type Point2");
26+
}
27+
Converter::unwrapPtr(info.This())->locations = locations;
28+
}
29+
30+
static NAN_GETTER(confidencesGet) {
31+
FF_RETURN(DoubleArrayConverter::wrap(Converter::unwrap(info.This()).confidences));
32+
}
33+
34+
static NAN_SETTER(confidencesSet) {
35+
std::vector<double> confidences;
36+
if (DoubleArrayConverter::unwrap(&confidences, value)) {
37+
return Nan::ThrowError("expected confidences to be an Array of type Number");
38+
}
39+
Converter::unwrapPtr(info.This())->confidences = confidences;
40+
}
41+
42+
static Nan::Persistent<v8::FunctionTemplate> constructor;
43+
44+
cv::DetectionROI* getNativeObjectPtr() { return &detectionROI; }
45+
cv::DetectionROI getNativeObject() { return detectionROI; }
46+
47+
typedef InstanceConverter<DetectionROI, cv::DetectionROI> Converter;
48+
49+
static const char* getClassName() {
50+
return "DetectionROI";
51+
}
52+
};
53+
54+
#endif

0 commit comments

Comments
 (0)