|
1 |
| -import { resolve } from "path"; |
2 |
| -import { Region } from "../../region.class"; |
3 |
| -import { ImageProcessor } from "./image-processor.class"; |
4 |
| -import { ImageReader } from "./image-reader.class"; |
| 1 | +import {resolve} from "path"; |
| 2 | +import {Region} from "../../region.class"; |
| 3 | +import {ImageReader} from "./image-reader.class"; |
| 4 | +import {fromImageWithAlphaChannel, fromImageWithoutAlphaChannel} from "./image-processor.class"; |
5 | 5 |
|
6 | 6 | describe("ImageProcessor", () => {
|
7 |
| - it("should allow to create a cv.Mat from an Image with alpha channel, alpha channel is dropped", async () => { |
8 |
| - // GIVEN |
9 |
| - const imageReader = new ImageReader(); |
10 |
| - const imagePath = resolve(__dirname, "./__mocks__/alpha_channel.png"); |
11 |
| - const image = await imageReader.load(imagePath); |
| 7 | + it("should allow to create a cv.Mat from an Image with alpha channel, alpha channel is dropped", async () => { |
| 8 | + // GIVEN |
| 9 | + const imageReader = new ImageReader(); |
| 10 | + const imagePath = resolve(__dirname, "./__mocks__/alpha_channel.png"); |
| 11 | + const image = await imageReader.load(imagePath); |
12 | 12 |
|
13 |
| - // WHEN |
14 |
| - const mat = await ImageProcessor.fromImageWithAlphaChannel(image); |
| 13 | + // WHEN |
| 14 | + const mat = await fromImageWithAlphaChannel(image); |
15 | 15 |
|
16 |
| - // THEN |
17 |
| - expect(image.hasAlphaChannel).toBeTruthy(); |
18 |
| - expect(mat.channels).toEqual(3); |
19 |
| - expect(mat.rows).toEqual(image.height); |
20 |
| - expect(mat.cols).toEqual(image.width); |
21 |
| - expect(mat.empty).toBeFalsy(); |
22 |
| - }); |
| 16 | + // THEN |
| 17 | + expect(image.hasAlphaChannel).toBeTruthy(); |
| 18 | + expect(mat.channels).toEqual(3); |
| 19 | + expect(mat.rows).toEqual(image.height); |
| 20 | + expect(mat.cols).toEqual(image.width); |
| 21 | + expect(mat.empty).toBeFalsy(); |
| 22 | + }); |
23 | 23 |
|
24 |
| - it("should allow to create a cv.Mat from an Image without alpha channel", async () => { |
25 |
| - // GIVEN |
26 |
| - const imageReader = new ImageReader(); |
27 |
| - const imagePath = resolve(__dirname, "./__mocks__/mouse.png"); |
28 |
| - const image = await imageReader.load(imagePath); |
| 24 | + it("should allow to create a cv.Mat from an Image without alpha channel", async () => { |
| 25 | + // GIVEN |
| 26 | + const imageReader = new ImageReader(); |
| 27 | + const imagePath = resolve(__dirname, "./__mocks__/mouse.png"); |
| 28 | + const image = await imageReader.load(imagePath); |
29 | 29 |
|
30 |
| - // WHEN |
31 |
| - const mat = await ImageProcessor.fromImageWithoutAlphaChannel(image); |
| 30 | + // WHEN |
| 31 | + const mat = await fromImageWithoutAlphaChannel(image); |
32 | 32 |
|
33 |
| - // THEN |
34 |
| - expect(image.hasAlphaChannel).toBeFalsy(); |
35 |
| - expect(mat.channels).toEqual(3); |
36 |
| - expect(mat.rows).toEqual(image.height); |
37 |
| - expect(mat.cols).toEqual(image.width); |
38 |
| - expect(mat.empty).toBeFalsy(); |
39 |
| - }); |
| 33 | + // THEN |
| 34 | + expect(image.hasAlphaChannel).toBeFalsy(); |
| 35 | + expect(mat.channels).toEqual(3); |
| 36 | + expect(mat.rows).toEqual(image.height); |
| 37 | + expect(mat.cols).toEqual(image.width); |
| 38 | + expect(mat.empty).toBeFalsy(); |
| 39 | + }); |
40 | 40 | });
|
41 | 41 |
|
42 | 42 | describe("ImageProcessor with ROI", () => {
|
43 |
| - it("negative left or top values are updated to 0", async () => { |
44 |
| - // GIVEN |
45 |
| - const imageReader = new ImageReader(); |
46 |
| - const imagePath = resolve(__dirname, "./__mocks__/mouse.png"); |
47 |
| - const image = await imageReader.load(imagePath); |
| 43 | + it("negative left or top values are updated to 0", async () => { |
| 44 | + // GIVEN |
| 45 | + const imageReader = new ImageReader(); |
| 46 | + const imagePath = resolve(__dirname, "./__mocks__/mouse.png"); |
| 47 | + const image = await imageReader.load(imagePath); |
48 | 48 |
|
49 |
| - // WHEN |
50 |
| - const mat = await ImageProcessor.fromImageWithoutAlphaChannel( |
51 |
| - image, |
52 |
| - new Region(-100, -100, 10, 10) |
53 |
| - ); |
| 49 | + // WHEN |
| 50 | + const mat = await fromImageWithoutAlphaChannel( |
| 51 | + image, |
| 52 | + new Region(-100, -100, 10, 10) |
| 53 | + ); |
54 | 54 |
|
55 |
| - // THEN |
56 |
| - expect(image.hasAlphaChannel).toBeFalsy(); |
57 |
| - expect(mat.channels).toEqual(3); |
58 |
| - expect(mat.rows).toEqual(10); |
59 |
| - expect(mat.cols).toEqual(10); |
60 |
| - expect(mat.empty).toBeFalsy(); |
61 |
| - }); |
| 55 | + // THEN |
| 56 | + expect(image.hasAlphaChannel).toBeFalsy(); |
| 57 | + expect(mat.channels).toEqual(3); |
| 58 | + expect(mat.rows).toEqual(10); |
| 59 | + expect(mat.cols).toEqual(10); |
| 60 | + expect(mat.empty).toBeFalsy(); |
| 61 | + }); |
62 | 62 |
|
63 |
| - it("values bigger than the input are updated to width and height", async () => { |
64 |
| - // GIVEN |
65 |
| - const imageReader = new ImageReader(); |
66 |
| - const imagePath = resolve(__dirname, "./__mocks__/mouse.png"); |
67 |
| - const image = await imageReader.load(imagePath); |
| 63 | + it("values bigger than the input are updated to width and height", async () => { |
| 64 | + // GIVEN |
| 65 | + const imageReader = new ImageReader(); |
| 66 | + const imagePath = resolve(__dirname, "./__mocks__/mouse.png"); |
| 67 | + const image = await imageReader.load(imagePath); |
68 | 68 |
|
69 |
| - // WHEN |
70 |
| - const mat = await ImageProcessor.fromImageWithoutAlphaChannel( |
71 |
| - image, |
72 |
| - new Region(10, 10, image.width * 2, image.height * 2) |
73 |
| - ); |
| 69 | + // WHEN |
| 70 | + const mat = await fromImageWithoutAlphaChannel( |
| 71 | + image, |
| 72 | + new Region(10, 10, image.width * 2, image.height * 2) |
| 73 | + ); |
74 | 74 |
|
75 |
| - // THEN |
76 |
| - expect(image.hasAlphaChannel).toBeFalsy(); |
77 |
| - expect(mat.channels).toEqual(3); |
78 |
| - expect(mat.rows).toEqual(image.height - 10); |
79 |
| - expect(mat.cols).toEqual(image.width - 10); |
80 |
| - expect(mat.empty).toBeFalsy(); |
81 |
| - }); |
| 75 | + // THEN |
| 76 | + expect(image.hasAlphaChannel).toBeFalsy(); |
| 77 | + expect(mat.channels).toEqual(3); |
| 78 | + expect(mat.rows).toEqual(image.height - 10); |
| 79 | + expect(mat.cols).toEqual(image.width - 10); |
| 80 | + expect(mat.empty).toBeFalsy(); |
| 81 | + }); |
82 | 82 | });
|
0 commit comments