|
| 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