Skip to content

Commit 6d1b0c5

Browse files
committed
(#68) Moved edge detection in images to separate function
1 parent 918dad5 commit 6d1b0c5

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

Diff for: lib/provider/opencv/find-edges.function.spec.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import * as cv from "opencv4nodejs-prebuilt";
2+
import { mockPartial } from "sneer";
3+
import { findEdges } from "./find-edges.function";
4+
5+
describe("findEdges", () => {
6+
it("should convert an image to grayscale and run Canny edge detection", async () => {
7+
// GIVEN
8+
const grayImageMock = mockPartial<cv.Mat>({
9+
cannyAsync: jest.fn()
10+
});
11+
const inputImageMock = mockPartial<cv.Mat>({
12+
cvtColorAsync: jest.fn(() => Promise.resolve(grayImageMock))
13+
});
14+
15+
// WHEN
16+
await findEdges(inputImageMock);
17+
18+
// THEN
19+
expect(inputImageMock.cvtColorAsync).toBeCalledWith(cv.COLOR_BGR2GRAY);
20+
expect(grayImageMock.cannyAsync).toBeCalledWith(50, 200);
21+
});
22+
});

Diff for: lib/provider/opencv/find-edges.function.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import * as cv from "opencv4nodejs-prebuilt";
2+
3+
export const findEdges = async (image: cv.Mat): Promise<cv.Mat> => {
4+
const gray = await image.cvtColorAsync(cv.COLOR_BGR2GRAY);
5+
return gray.cannyAsync(50, 200);
6+
};

0 commit comments

Comments
 (0)