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

Commit 067f17f

Browse files
added quick testcases for SuperpixelSLIC and SuperpixelLSC + added SuperpixelSLIC algorithm constants
1 parent c3f8e3d commit 067f17f

File tree

5 files changed

+60
-4
lines changed

5 files changed

+60
-4
lines changed

cc/modules/ximgproc/SuperpixelLSC.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ NAN_METHOD(SuperpixelLSC::New) {
3535
FF_ARG_INSTANCE(0, self->img, Mat::constructor, FF_UNWRAP_MAT_AND_GET);
3636
FF_ARG_INT_IFDEF(1, self->regionSize, 10);
3737
FF_ARG_INT_IFDEF(2, self->ratio, 0.075);
38-
38+
3939
self->Wrap(info.Holder());
4040
self->superpixelLsc = cv::ximgproc::createSuperpixelLSC(
4141
self->img,

cc/modules/ximgproc/SuperpixelSLIC.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ NAN_METHOD(SuperpixelSLIC::New) {
3434
SuperpixelSLIC* self = new SuperpixelSLIC();
3535

3636
FF_ARG_INSTANCE(0, self->img, Mat::constructor, FF_UNWRAP_MAT_AND_GET);
37-
FF_ARG_INT(1, self->algorithm);
37+
FF_ARG_INT_IFDEF(1, self->algorithm, cv::ximgproc::SLICO);
3838
FF_ARG_INT_IFDEF(2, self->regionSize, 10);
3939
FF_ARG_INT_IFDEF(3, self->ruler, 10.0);
4040

cc/modules/ximgproc/ximgproc.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ NAN_MODULE_INIT(XImgproc::Init) {
1313
#if CV_MINOR_VERSION > 0
1414
SuperpixelSLIC::Init(target);
1515
SuperpixelLSC::Init(target);
16+
FF_SET_JS_PROP(target, SLIC, Nan::New<v8::Integer>(cv::ximgproc::SLIC));
17+
FF_SET_JS_PROP(target, SLICO, Nan::New<v8::Integer>(cv::ximgproc::SLICO));
1618
#endif
1719
}
1820

doc/ximgproc/SuperpixelSLIC.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
## Constructors
1919
``` javascript
20-
SuperpixelSLIC : new SuperpixelSLIC(Mat img, Int algorithm, Int regionSize = 10, Number ruler = 10)
20+
SuperpixelSLIC : new SuperpixelSLIC(Mat img, Int algorithm = cv.SLICO, Int regionSize = 10, Number ruler = 10)
2121
```
2222

2323
## Methods

test/tests/modules/imgproc/ximgproc.test.js

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const cv = global.dut;
22
const { assertMetaData, assertPropsWithValue, funcShouldRequireArgs, readTestImage } = global.utils;
33
const { assert, expect } = require('chai');
44

5-
describe('ximgproc', () => {
5+
describe.only('ximgproc', () => {
66
if (!cv.xmodules.ximgproc) {
77
it('compiled without ximgproc');
88
return;
@@ -43,4 +43,58 @@ describe('ximgproc', () => {
4343
});
4444
});
4545
});
46+
47+
if (cv.version.minor > 0) {
48+
describe('SuperpixelSLIC', () => {
49+
const algorithm = cv.SLICO;
50+
51+
describe('constructor', () => {
52+
funcShouldRequireArgs(() => new cv.SuperpixelSLIC());
53+
54+
it('should be constructable with required args', () => {
55+
const superpixel = new cv.SuperpixelSLIC(testImg, algorithm);
56+
expect(superpixel).to.have.property('img').instanceOf(cv.Mat);
57+
assertMetaData(testImg)(superpixel.img);
58+
assertPropsWithValue(superpixel)({
59+
algorithm
60+
});
61+
});
62+
});
63+
64+
describe('iterate', () => {
65+
it('should iterate with default values', () => {
66+
const superpixel = new cv.SuperpixelSLIC(testImg, algorithm);
67+
superpixel.iterate();
68+
assert(superpixel.numCalculatedSuperpixels > 0, 'no superpixels calculated');
69+
assertPropsWithValue(superpixel.labels)({
70+
rows: testImg.rows, cols: testImg.cols, type: cv.CV_32S
71+
});
72+
});
73+
});
74+
});
75+
76+
77+
describe('SuperpixelLSC', () => {
78+
describe('constructor', () => {
79+
funcShouldRequireArgs(() => new cv.SuperpixelLSC());
80+
81+
it('should be constructable with required args', () => {
82+
const superpixel = new cv.SuperpixelLSC(testImg);
83+
expect(superpixel).to.have.property('img').instanceOf(cv.Mat);
84+
assertMetaData(testImg)(superpixel.img);
85+
});
86+
});
87+
88+
describe('iterate', () => {
89+
it('should iterate with default values', () => {
90+
const superpixel = new cv.SuperpixelLSC(testImg);
91+
superpixel.iterate();
92+
assert(superpixel.numCalculatedSuperpixels > 0, 'no superpixels calculated');
93+
assertPropsWithValue(superpixel.labels)({
94+
rows: testImg.rows, cols: testImg.cols, type: cv.CV_32S
95+
});
96+
});
97+
});
98+
});
99+
}
46100
});

0 commit comments

Comments
 (0)