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

Commit 8df1253

Browse files
committed
cc, test: fix clang warnings
1 parent 0a15cfa commit 8df1253

File tree

10 files changed

+60
-24
lines changed

10 files changed

+60
-24
lines changed

cc/core/Mat.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ NAN_METHOD(Mat::New) {
120120
if (info.Length() == 1 && info[0]->IsArray()) {
121121
FF_ARR jsChannelMats = FF_ARR::Cast(info[0]);
122122
std::vector<cv::Mat> channels;
123-
for (int i = 0; i < jsChannelMats->Length(); i++) {
123+
for (uint i = 0; i < jsChannelMats->Length(); i++) {
124124
FF_OBJ jsChannelMat = FF_CAST_OBJ(jsChannelMats->Get(i));
125125
FF_REQUIRE_INSTANCE(constructor, jsChannelMat,
126126
FF_NEW_STRING("expected channel " + std::to_string(i) + " to be an instance of Mat"));

cc/core/MatImgproc.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ NAN_METHOD(MatImgproc::DrawContours) {
134134

135135
std::vector<std::vector<cv::Point>> contours;
136136
std::vector<cv::Vec4i> hierarchy;
137-
for (int i = 0; i < jsContours->Length(); i++) {
137+
for (uint i = 0; i < jsContours->Length(); i++) {
138138
FF_OBJ jsContour = jsContours->Get(i)->ToObject();
139139
contours.push_back(FF_UNWRAP_CONTOUR_AND_GET(jsContour));
140140
hierarchy.push_back(FF_UNWRAP_CONTOUR(jsContour)->hierarchy);

cc/core/Point.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Point : public Nan::ObjectWrap {
3939
template<typename type>
4040
static v8::Local<v8::Array> packJSPoint2Array(std::vector<cv::Point_<type>> pts) {
4141
v8::Local<v8::Array> jsPts = Nan::New<v8::Array>(pts.size());
42-
for (int i = 0; i < jsPts->Length(); i++) {
42+
for (uint i = 0; i < jsPts->Length(); i++) {
4343
v8::Local<v8::Object> jsPt2 = FF_NEW_INSTANCE(Point2::constructor);
4444
FF_UNWRAP_PT2_AND_GET(jsPt2) = pts.at(i);
4545
jsPts->Set(i, jsPt2);
@@ -59,4 +59,4 @@ class Point : public Nan::ObjectWrap {
5959
};
6060
};
6161

62-
#endif
62+
#endif

cc/core/Vec.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ class Vec : public Nan::ObjectWrap {
2929
vecs.push_back(FF_UNWRAP_VEC3_AND_GET(Nan::To<v8::Object>(jsVec->Get(i)).ToLocalChecked()));
3030
}
3131
return vecs;
32-
};
33-
32+
};
33+
3434
static std::vector<cv::Vec4d> unpackJSVec4Array(FF_ARR jsVec) {
3535
std::vector<cv::Vec4d> vecs;
3636
for (uint i = 0; i < jsVec->Length(); i++) {
@@ -41,7 +41,7 @@ class Vec : public Nan::ObjectWrap {
4141

4242
static v8::Local<v8::Array> packJSVec4Array(std::vector<cv::Vec4d> vecs) {
4343
v8::Local<v8::Array> jsVecs = Nan::New<v8::Array>(vecs.size());
44-
for (int i = 0; i < jsVecs->Length(); i++) {
44+
for (uint i = 0; i < jsVecs->Length(); i++) {
4545
v8::Local<v8::Object> jsVec4 = FF_NEW_INSTANCE(Vec4::constructor);
4646
FF_UNWRAP_VEC4_AND_GET(jsVec4) = vecs.at(i);
4747
jsVecs->Set(i, jsVec4);
@@ -53,4 +53,4 @@ class Vec : public Nan::ObjectWrap {
5353
static Nan::Persistent<v8::FunctionTemplate> constructor;
5454
};
5555

56-
#endif
56+
#endif

cc/core/core.cc

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@
22
#include "coreBindings.h"
33

44
#define FF_CV_PREDICATE(ff_name, ff_type, ff_ctor, ff_unwrapper) \
5-
struct ff_name##Predicate { \
6-
v8::Local<v8::Function> cb; \
7-
ff_name##Predicate(v8::Local<v8::Function> _cb) { \
8-
cb = _cb; \
9-
} \
10-
bool operator()(const ff_type& a, const ff_type& b) { \
11-
FF_VAL cbArgs[2]; \
12-
cbArgs[0] = FF_NEW_INSTANCE(ff_ctor); \
13-
cbArgs[1] = FF_NEW_INSTANCE(ff_ctor); \
5+
struct ff_name##Predicate { \
6+
v8::Local<v8::Function> cb; \
7+
ff_name##Predicate(v8::Local<v8::Function> _cb) { \
8+
cb = _cb; \
9+
} \
10+
bool operator()(const ff_type& a, const ff_type& b) { \
11+
FF_VAL cbArgs[2]; \
12+
cbArgs[0] = FF_NEW_INSTANCE(ff_ctor); \
13+
cbArgs[1] = FF_NEW_INSTANCE(ff_ctor); \
1414
ff_unwrapper(cbArgs[0]->ToObject()) = a; \
1515
ff_unwrapper(cbArgs[1]->ToObject()) = b; \
16-
return cb->Call(Nan::GetCurrentContext()->Global(), 2, cbArgs)->BooleanValue(); \
17-
} \
16+
Nan::AsyncResource resource("opencv4nodejs:Predicate::Constructor"); \
17+
return resource.runInAsyncScope(Nan::GetCurrentContext()->Global(), \
18+
cb, 2, cbArgs).ToLocalChecked()->BooleanValue(); \
19+
} \
1820
}
1921

2022
FF_CV_PREDICATE(Point2, cv::Point2d, Point2::constructor, FF_UNWRAP_PT2_AND_GET);

cc/modules/face/Facemark.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,10 @@ bool Facemark::detector(cv::InputArray image, cv::OutputArray faces,
165165
v8::Local<v8::Value> jsMat = Mat::Converter::wrap(frame);
166166

167167
v8::Local<v8::Value> argv[] = {jsMat};
168-
FF_OBJ jsObject = callback->Call(1, argv)->ToObject();
168+
169+
Nan::AsyncResource resource("opencv4nodejs:Facemark::Detector");
170+
FF_OBJ jsObject = resource.runInAsyncScope(Nan::GetCurrentContext()->Global(), **callback, 1, argv)
171+
.ToLocalChecked()->ToObject();
169172

170173
std::vector<cv::Rect> _faces;
171174
ObjectArrayConverter<Rect, cv::Rect>::unwrap(&_faces, jsObject);

cc/modules/face/FacemarkLBFParams.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class FacemarkLBFParams : public Nan::ObjectWrap {
3333

3434
static NAN_GETTER(pupilsGet) {
3535
v8::Local<v8::Array> jsArr = Nan::New<v8::Array>(2);
36-
for (int i = 0; i < jsArr->Length(); i++) {
36+
for (uint i = 0; i < jsArr->Length(); i++) {
3737
jsArr->Set(i, ArrayConverterType<IntTypeConverter, int>::wrap(
3838
Nan::ObjectWrap::Unwrap<FacemarkLBFParams>(info.This())->params.pupils[i])
3939
);
@@ -44,7 +44,7 @@ class FacemarkLBFParams : public Nan::ObjectWrap {
4444
static NAN_SETTER(pupilsSet) {
4545
FF_METHOD_CONTEXT("pupils");
4646
v8::Local<v8::Array> jsArr = v8::Local<v8::Array>::Cast(value);
47-
for (int i = 0; i < jsArr->Length(); i++) {
47+
for (uint i = 0; i < jsArr->Length(); i++) {
4848
std::vector<int> vec;
4949
Nan::TryCatch tryCatch;
5050
if (ArrayConverterType<IntTypeConverter, int>::unwrap(&vec, jsArr->Get(i))) {

cc/modules/features2d/features2d.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ NAN_METHOD(Features2d::DrawMatches) {
9696
FF_UNPACK_KEYPOINT_ARRAY(kps1, jsKps1);
9797
FF_UNPACK_KEYPOINT_ARRAY(kps2, jsKps2);
9898
std::vector<cv::DMatch> dMatches;
99-
for (int i = 0; i < jsMatches->Length(); i++) {
99+
for (uint i = 0; i < jsMatches->Length(); i++) {
100100
DescriptorMatch* match = FF_UNWRAP(FF_CAST_OBJ(jsMatches->Get(i)), DescriptorMatch);
101101
dMatches.push_back(match->dmatch);
102102
}

cc/modules/imgproc/Contour.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ NAN_METHOD(Contour::New) {
4949
if (info.Length() == 1) {
5050
FF_ARR jsPts = FF_ARR::Cast(info[0]);
5151
self->contour.reserve(jsPts->Length());
52-
for (int i = 0; i < jsPts->Length(); i++) {
52+
for (uint i = 0; i < jsPts->Length(); i++) {
5353
cv::Point2d cv_pt;
5454
auto jsPt = jsPts->Get(i);
5555
if (jsPt->IsArray()) {

test/tests/core/core.test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ const {
66
} = global.utils;
77
const { expect } = require('chai');
88

9+
let asyncHooks = null
10+
11+
try {
12+
asyncHooks = require('async_hooks')
13+
} catch (e) {
14+
//
15+
}
16+
917
const partitionTests = (createInstance) => {
1018
it('should return labels and numLabels', () => {
1119
const { labels, numLabels } = cv.partition([createInstance(), createInstance()], () => true);
@@ -161,4 +169,27 @@ describe('core', () => {
161169
expectOutput
162170
});
163171
});
172+
173+
if (asyncHooks) {
174+
describe('async_hooks', () => {
175+
it('should trigger `init` callback in async_hooks', () => {
176+
let typeFound = false
177+
const hook = asyncHooks.createHook({
178+
init: (asyncId, type, triggerAsyncId, resource) => {
179+
if (type.indexOf('opencv4nodejs') === 0) {
180+
typeFound = true
181+
hook.disable()
182+
}
183+
},
184+
})
185+
hook.enable()
186+
187+
const createInstance = () => new cv.Point(0, 0)
188+
const num = 5;
189+
const instances = Array(num).fill(0).map(() => createInstance());
190+
const { labels, numLabels } = cv.partition(instances, () => true);
191+
expect(typeFound).to.be.equal(true)
192+
})
193+
})
194+
}
164195
});

0 commit comments

Comments
 (0)