Skip to content

Commit 686a5a0

Browse files
committed
(#57) Added tests to verify ROI checks
1 parent afdb0ea commit 686a5a0

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

lib/provider/opencv/image-processor.class.spec.ts

+43
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { resolve } from "path";
2+
import { Region } from "../../region.class";
23
import { ImageProcessor } from "./image-processor.class";
34
import { ImageReader } from "./image-reader.class";
45

@@ -37,3 +38,45 @@ describe("ImageProcessor", () => {
3738
expect(mat.empty).toBeFalsy();
3839
});
3940
});
41+
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);
48+
49+
// WHEN
50+
const mat = await ImageProcessor.fromImageWithoutAlphaChannel(
51+
image,
52+
new Region(-100, -100, 10, 10)
53+
);
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+
});
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);
68+
69+
// WHEN
70+
const mat = await ImageProcessor.fromImageWithoutAlphaChannel(
71+
image,
72+
new Region(10, 10, image.width * 2, image.height * 2)
73+
);
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+
});
82+
});

0 commit comments

Comments
 (0)