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

Commit 0ab092d

Browse files
fixed segfault in HOG bindings due to invoking HOG copy constructor
1 parent 211288d commit 0ab092d

File tree

3 files changed

+111
-105
lines changed

3 files changed

+111
-105
lines changed

cc/modules/objdetect/HOGDescriptor.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ NAN_METHOD(HOGDescriptor::New) {
8585
}
8686

8787
HOGDescriptor* self = new HOGDescriptor();
88-
self->hog = cv::HOGDescriptor(
88+
self->hog = std::make_shared<cv::HOGDescriptor>(
8989
winSize,
9090
blockSize,
9191
blockStride,
@@ -115,7 +115,7 @@ NAN_METHOD(HOGDescriptor::GetDefaultPeopleDetector) {
115115
}
116116

117117
NAN_METHOD(HOGDescriptor::CheckDetectorSize) {
118-
FF_RETURN(Nan::New(HOGDescriptor::Converter::unwrap(info.This()).checkDetectorSize()));
118+
FF_RETURN(Nan::New(HOGDescriptor::Converter::unwrap(info.This())->checkDetectorSize()));
119119
}
120120

121121
NAN_METHOD(HOGDescriptor::SetSVMDetector) {
@@ -124,22 +124,23 @@ NAN_METHOD(HOGDescriptor::SetSVMDetector) {
124124
if (!FF_HAS_ARG(0) || FloatArrayConverter::unwrap(&detector, info[0])) {
125125
FF_THROW("expected detector to be an Array of type Number");
126126
}
127-
HOGDescriptor::Converter::unwrapPtr(info.This())->setSVMDetector(detector);
127+
HOGDescriptor::Converter::unwrap(info.This())->setSVMDetector(detector);
128128
}
129129

130130
NAN_METHOD(HOGDescriptor::Save) {
131131
FF_METHOD_CONTEXT("HOGDescriptor::Save");
132132
FF_ARG_STRING(0, std::string path);
133-
FF_UNWRAP(info.This(), HOGDescriptor)->hog.save(path);
133+
FF_UNWRAP(info.This(), HOGDescriptor)->hog->save(path);
134134
}
135135

136136
NAN_METHOD(HOGDescriptor::Load) {
137137
FF_METHOD_CONTEXT("HOGDescriptor::Load");
138138
FF_ARG_STRING(0, std::string path);
139-
FF_UNWRAP(info.This(), HOGDescriptor)->hog.load(path);
139+
FF_UNWRAP(info.This(), HOGDescriptor)->hog->load(path);
140140
}
141141

142142
NAN_METHOD(HOGDescriptor::Compute) {
143+
std::cout << "Compute" << std::endl;
143144
FF::SyncBinding(
144145
std::make_shared<HOGDescriptorBindings::ComputeWorker>(HOGDescriptor::Converter::unwrap(info.This())),
145146
"HOGDescriptor::Compute",

cc/modules/objdetect/HOGDescriptor.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,31 @@
1313

1414
class HOGDescriptor : public Nan::ObjectWrap {
1515
public:
16-
cv::HOGDescriptor hog;
16+
std::shared_ptr<cv::HOGDescriptor> hog;
1717

1818
static Nan::Persistent<v8::FunctionTemplate> constructor;
1919

20-
cv::HOGDescriptor* getNativeObjectPtr() { return &hog; }
21-
cv::HOGDescriptor getNativeObject() { return hog; }
20+
cv::HOGDescriptor* getNativeObjectPtr() { return hog.get(); }
21+
std::shared_ptr<cv::HOGDescriptor> getNativeObject() { return hog; }
2222

23-
typedef InstanceConverter<HOGDescriptor, cv::HOGDescriptor> Converter;
23+
typedef InstanceConverter<HOGDescriptor, std::shared_ptr<cv::HOGDescriptor>> Converter;
2424

2525
static const char* getClassName() {
2626
return "HOGDescriptor";
2727
}
2828

29-
static FF_GETTER_JSOBJ(HOGDescriptor, winSize, hog.winSize, FF_UNWRAP_SIZE_AND_GET, Size::constructor);
30-
static FF_GETTER_JSOBJ(HOGDescriptor, blockSize, hog.blockSize, FF_UNWRAP_SIZE_AND_GET, Size::constructor);
31-
static FF_GETTER_JSOBJ(HOGDescriptor, blockStride, hog.blockStride, FF_UNWRAP_SIZE_AND_GET, Size::constructor);
32-
static FF_GETTER_JSOBJ(HOGDescriptor, cellSize, hog.cellSize, FF_UNWRAP_SIZE_AND_GET, Size::constructor);
33-
static FF_GETTER(HOGDescriptor, nbins, hog.nbins);
34-
static FF_GETTER(HOGDescriptor, derivAperture, hog.derivAperture);
35-
static FF_GETTER(HOGDescriptor, histogramNormType, hog.histogramNormType);
36-
static FF_GETTER(HOGDescriptor, nlevels, hog.nlevels);
37-
static FF_GETTER(HOGDescriptor, winSigma, hog.winSigma);
38-
static FF_GETTER(HOGDescriptor, L2HysThreshold, hog.L2HysThreshold);
39-
static FF_GETTER(HOGDescriptor, gammaCorrection, hog.gammaCorrection);
40-
static FF_GETTER(HOGDescriptor, signedGradient, hog.signedGradient);
29+
static FF_GETTER_JSOBJ(HOGDescriptor, winSize, hog->winSize, FF_UNWRAP_SIZE_AND_GET, Size::constructor);
30+
static FF_GETTER_JSOBJ(HOGDescriptor, blockSize, hog->blockSize, FF_UNWRAP_SIZE_AND_GET, Size::constructor);
31+
static FF_GETTER_JSOBJ(HOGDescriptor, blockStride, hog->blockStride, FF_UNWRAP_SIZE_AND_GET, Size::constructor);
32+
static FF_GETTER_JSOBJ(HOGDescriptor, cellSize, hog->cellSize, FF_UNWRAP_SIZE_AND_GET, Size::constructor);
33+
static FF_GETTER(HOGDescriptor, nbins, hog->nbins);
34+
static FF_GETTER(HOGDescriptor, derivAperture, hog->derivAperture);
35+
static FF_GETTER(HOGDescriptor, histogramNormType, hog->histogramNormType);
36+
static FF_GETTER(HOGDescriptor, nlevels, hog->nlevels);
37+
static FF_GETTER(HOGDescriptor, winSigma, hog->winSigma);
38+
static FF_GETTER(HOGDescriptor, L2HysThreshold, hog->L2HysThreshold);
39+
static FF_GETTER(HOGDescriptor, gammaCorrection, hog->gammaCorrection);
40+
static FF_GETTER(HOGDescriptor, signedGradient, hog->signedGradient);
4141

4242
static NAN_MODULE_INIT(Init);
4343

0 commit comments

Comments
 (0)