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

Commit 6ec968d

Browse files
committed
cc: fix compatibility issues
1 parent 27614dc commit 6ec968d

File tree

5 files changed

+45
-25
lines changed

5 files changed

+45
-25
lines changed

cc/modules/dnn/NetBindings.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,11 @@ namespace NetBindings {
6868
}
6969

7070
bool unwrapOptionalArgs(Nan::NAN_METHOD_ARGS_TYPE info) {
71+
#if CV_VERSION_MINOR > 2
7172
if (FF_IS_ARRAY(info[0])) {
7273
return StringArrayConverter::optArg(0, &outBlobNames, info);
7374
}
74-
75+
#endif
7576
return (
7677
StringConverter::optArg(0, &outputName, info)
7778
);

cc/modules/dnn/dnn.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ NAN_MODULE_INIT(Dnn::Init) {
1919
Nan::SetMethod(target, "blobFromImageAsync", BlobFromImageAsync);
2020
Nan::SetMethod(target, "blobFromImages", BlobFromImages);
2121
Nan::SetMethod(target, "blobFromImagesAsync", BlobFromImagesAsync);
22+
#if CV_VERSION_MINOR > 3
2223
Nan::SetMethod(target, "NMSBoxes", NMSBoxes);
24+
#endif
2325
};
2426

2527
NAN_METHOD(Dnn::ReadNetFromTensorflow) {
@@ -86,12 +88,14 @@ NAN_METHOD(Dnn::BlobFromImagesAsync) {
8688
);
8789
}
8890

91+
#if CV_VERSION_MINOR > 3
8992
NAN_METHOD(Dnn::NMSBoxes) {
9093
FF::SyncBinding(
9194
std::make_shared<DnnBindings::NMSBoxes>(),
9295
"NMSBoxes",
9396
info
9497
);
9598
}
99+
#endif
96100

97101
#endif

cc/modules/dnn/dnn.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ class Dnn {
1111
public:
1212
static NAN_MODULE_INIT(Init);
1313

14-
static NAN_METHOD(ReadNetFromTensorflow);
15-
static NAN_METHOD(ReadNetFromTensorflowAsync);
16-
static NAN_METHOD(ReadNetFromCaffe);
17-
static NAN_METHOD(ReadNetFromCaffeAsync);
18-
static NAN_METHOD(BlobFromImage);
19-
static NAN_METHOD(BlobFromImageAsync);
20-
static NAN_METHOD(BlobFromImages);
21-
static NAN_METHOD(BlobFromImagesAsync);
14+
static NAN_METHOD(ReadNetFromTensorflow);
15+
static NAN_METHOD(ReadNetFromTensorflowAsync);
16+
static NAN_METHOD(ReadNetFromCaffe);
17+
static NAN_METHOD(ReadNetFromCaffeAsync);
18+
static NAN_METHOD(BlobFromImage);
19+
static NAN_METHOD(BlobFromImageAsync);
20+
static NAN_METHOD(BlobFromImages);
21+
static NAN_METHOD(BlobFromImagesAsync);
22+
#if CV_VERSION_MINOR > 3
2223
static NAN_METHOD(NMSBoxes);
24+
#endif
2325
};
2426

2527
#endif

cc/modules/dnn/dnnBindings.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,21 @@ namespace DnnBindings {
8181
cv::Mat returnValue;
8282

8383
std::string executeCatchCvExceptionWorker() {
84+
#if CV_VERSION_MINOR > 3 && CV_VERSION_REVISION > 2
8485
if (isSingleImage) {
8586
returnValue = cv::dnn::blobFromImage(image, scalefactor, size, mean, swapRB, crop, ddepth);
8687
}
8788
else {
8889
returnValue = cv::dnn::blobFromImages(images, scalefactor, size, mean, swapRB, crop, ddepth);
8990
}
91+
#else
92+
if (isSingleImage) {
93+
returnValue = cv::dnn::blobFromImage(image, scalefactor, size, mean, swapRB, crop);
94+
}
95+
else {
96+
returnValue = cv::dnn::blobFromImages(images, scalefactor, size, mean, swapRB, crop);
97+
}
98+
#endif
9099
return "";
91100
}
92101

@@ -129,6 +138,7 @@ namespace DnnBindings {
129138
}
130139
};
131140

141+
#if CV_VERSION_MINOR > 3
132142
struct NMSBoxes : public CatchCvExceptionWorker {
133143
public:
134144
std::vector<cv::Rect> bboxes;
@@ -156,6 +166,7 @@ namespace DnnBindings {
156166
);
157167
}
158168
};
169+
#endif
159170
}
160171

161172
#endif

test/tests/modules/dnn/dnn.test.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,23 @@ describe('dnn', () => {
8383
});
8484
});
8585

86-
describe('NMSBoxes', () => {
87-
generateAPITests({
88-
getDut: () => cv,
89-
methodName: 'NMSBoxes',
90-
hasAsync: false,
91-
getRequiredArgs: () => ([
92-
[new cv.Rect(0, 0, 1, 1)],
93-
[1],
94-
0.5,
95-
0.4,
96-
]),
97-
expectOutput: (res) => {
98-
expect(res).to.be.instanceOf(Array);
99-
expect(res[0]).to.be.equal(0);
100-
},
86+
if (cv.version.minor > 3) {
87+
describe('NMSBoxes', () => {
88+
generateAPITests({
89+
getDut: () => cv,
90+
methodName: 'NMSBoxes',
91+
hasAsync: false,
92+
getRequiredArgs: () => ([
93+
[new cv.Rect(0, 0, 1, 1)],
94+
[1],
95+
0.5,
96+
0.4,
97+
]),
98+
expectOutput: (res) => {
99+
expect(res).to.be.instanceOf(Array);
100+
expect(res[0]).to.be.equal(0);
101+
},
102+
});
101103
});
102-
});
104+
}
103105
});

0 commit comments

Comments
 (0)