forked from udarrr/opencv4nodejs-prebuilt-install
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSuperpixelLSC.cc
69 lines (53 loc) · 2.31 KB
/
SuperpixelLSC.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "opencv_modules.h"
#ifdef HAVE_OPENCV_XIMGPROC
#include "SuperpixelLSC.h"
#if CV_VERSION_GREATER_EQUAL(3, 1, 0)
Nan::Persistent<v8::FunctionTemplate> SuperpixelLSC::constructor;
NAN_MODULE_INIT(SuperpixelLSC::Init) {
v8::Local<v8::FunctionTemplate> ctor = Nan::New<v8::FunctionTemplate>(SuperpixelLSC::New);
v8::Local<v8::ObjectTemplate> instanceTemplate = ctor->InstanceTemplate();
constructor.Reset(ctor);
instanceTemplate->SetInternalFieldCount(1);
ctor->SetClassName(Nan::New("SuperpixelLSC").ToLocalChecked());
Nan::SetAccessor(instanceTemplate, Nan::New("image").ToLocalChecked(), image_getter);
Nan::SetAccessor(instanceTemplate, Nan::New("labels").ToLocalChecked(), labels_getter);
Nan::SetAccessor(instanceTemplate, Nan::New("labelContourMask").ToLocalChecked(), labelContourMask_getter);
Nan::SetAccessor(instanceTemplate, Nan::New("region_size").ToLocalChecked(), region_size_getter);
Nan::SetAccessor(instanceTemplate, Nan::New("ratio").ToLocalChecked(), ratio_getter);
Nan::SetAccessor(instanceTemplate, Nan::New("numCalculatedSuperpixels").ToLocalChecked(), numCalculatedSuperpixels_getter);
Nan::SetPrototypeMethod(ctor, "iterate", SuperpixelLSC::Iterate);
Nan::Set(target,Nan::New("SuperpixelLSC").ToLocalChecked(), FF::getFunction(ctor));
};
NAN_METHOD(SuperpixelLSC::New) {
FF::TryCatch tryCatch("SuperpixelLSC::New");
FF_ASSERT_CONSTRUCT_CALL();
SuperpixelLSC::NewWorker worker;
if (worker.applyUnwrappers(info)) {
return tryCatch.reThrow();
}
SuperpixelLSC* self = new SuperpixelLSC();
self->image = worker.image;
self->region_size = worker.region_size;
self->ratio = worker.ratio;
self->self = cv::ximgproc::createSuperpixelLSC(
worker.image,
worker.region_size,
worker.ratio
);
self->Wrap(info.Holder());
info.GetReturnValue().Set(info.Holder());
}
NAN_METHOD(SuperpixelLSC::Iterate) {
FF::TryCatch tryCatch("SuperpixelLSC::Iterate");
uint iterations = 10;
if (FF::UintConverter::optArg(0, &iterations, info)) {
return tryCatch.reThrow();
}
SuperpixelLSC* self = Nan::ObjectWrap::Unwrap<SuperpixelLSC>(info.This());
self->self->iterate((int)iterations);
self->self->getLabels(self->labels);
self->numCalculatedSuperpixels = self->self->getNumberOfSuperpixels();
self->self->getLabelContourMask(self->labelContourMask, false);
}
#endif
#endif // HAVE_OPENCV_XIMGPROC