Skip to content

Commit 375fc2a

Browse files
committed
Add: cv.inpaint: tests
1 parent dac1af5 commit 375fc2a

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
const cv = global.dut;
2+
const {
3+
assertError,
4+
assertPropsWithValue,
5+
assertMetaData,
6+
funcShouldRequireArgs,
7+
readTestImage,
8+
generateAPITests
9+
} = global.utils;
10+
const { expect } = require('chai');
11+
12+
describe('photo', () => {
13+
14+
describe('inpaint', () => {
15+
16+
it('should have constants', () => {
17+
expect(isNaN(cv.INPAINT_TELEA)).to.be.equal(false);
18+
expect(isNaN(cv.INPAINT_NS)).to.be.equal(false);
19+
});
20+
21+
22+
it('should perform inpainting', () => {
23+
24+
// construct a black image with a white dot in the middle
25+
const imgData = new Array(7*7).fill(0);
26+
imgData[7 * 3 + 3] = 255;
27+
const image = new cv.Mat(new Buffer(imgData), 7,7,cv.CV_8U);
28+
// construct the mask from the same image (since we want to inpaint the white dot)
29+
const mask = image.copy();
30+
31+
// perform inpainting
32+
const inpainted = cv.inpaint(image, mask, 3, cv.INPAINT_TELEA);
33+
34+
// now the result should be all black
35+
const sum = inpainted.sum();
36+
37+
// so sum should be 0
38+
expect(sum).to.be.equal(0);
39+
});
40+
41+
it('should perform inpainting async', (done) => {
42+
43+
// construct a black image with a white dot in the middle
44+
const imgData = new Array(7*7).fill(0);
45+
imgData[7 * 3 + 3] = 255;
46+
const image = new cv.Mat(new Buffer(imgData), 7,7,cv.CV_8U);
47+
// construct the mask from the same image (since we want to inpaint the white dot)
48+
const mask = image.copy();
49+
50+
// perform inpainting
51+
cv.inpaintAsync(image, mask, 3, cv.INPAINT_TELEA)
52+
.then(inpainted => {
53+
// now the result should be all black
54+
const sum = inpainted.sum();
55+
56+
// so sum should be 0
57+
expect(sum).to.be.equal(0);
58+
59+
done();
60+
}).catch(done);
61+
});
62+
})
63+
});

0 commit comments

Comments
 (0)