Skip to content

Commit 8fd761a

Browse files
committed
(#68) Updated scaled image search
1 parent 36629e7 commit 8fd761a

File tree

4 files changed

+220
-179
lines changed

4 files changed

+220
-179
lines changed

Diff for: lib/provider/opencv/__mocks__/needle.png

8.85 KB
Loading

Diff for: lib/provider/opencv/template-matching-finder.class.spec.ts

+16-12
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,42 @@ describe("Template-matching finder", () => {
1010
// GIVEN
1111
const imageLoader = new ImageReader();
1212
const SUT = new TemplateMatchingFinder();
13-
const imagePath = path.resolve(__dirname, "./__mocks__/mouse.png");
14-
const needle = await imageLoader.load(imagePath);
13+
const haystackPath = path.resolve(__dirname, "./__mocks__/mouse.png");
14+
const needlePath = path.resolve(__dirname, "./__mocks__/needle.png");
15+
const haystack = await imageLoader.load(haystackPath);
16+
const needle = await imageLoader.load(needlePath);
1517
const minConfidence = 0.99;
16-
const searchRegion = new Region(0, 0, needle.width, needle.height);
17-
const haystack = new Image(needle.width, needle.height, needle.data, 3);
18-
const matchRequest = new MatchRequest(haystack, imagePath, searchRegion, minConfidence);
18+
const searchRegion = new Region(0, 0, haystack.width, haystack.height);
19+
const matchRequest = new MatchRequest(haystack, needlePath, searchRegion, minConfidence);
20+
const expectedResult = new Region(16, 31, needle.width, needle.height);
1921

2022
// WHEN
2123
const result = await SUT.findMatch(matchRequest);
2224

2325
// THEN
2426
expect(result.confidence).toBeGreaterThanOrEqual(minConfidence);
25-
expect(result.location).toEqual(searchRegion);
27+
expect(result.location).toEqual(expectedResult);
2628
});
2729

2830
it("findMatch should return a match within a search region when present in image", async () => {
2931
// GIVEN
3032
const imageLoader = new ImageReader();
3133
const SUT = new TemplateMatchingFinder();
32-
const imagePath = path.resolve(__dirname, "./__mocks__/mouse.png");
33-
const needle = await imageLoader.load(imagePath);
34+
const haystackPath = path.resolve(__dirname, "./__mocks__/mouse.png");
35+
const needlePath = path.resolve(__dirname, "./__mocks__/needle.png");
36+
const haystack = await imageLoader.load(haystackPath);
37+
const needle = await imageLoader.load(needlePath);
3438
const minConfidence = 0.99;
35-
const searchRegion = new Region(10, 20, 100, 100);
36-
const haystack = new Image(needle.width, needle.height, needle.data, 3);
37-
const matchRequest = new MatchRequest(haystack, imagePath, searchRegion, minConfidence);
39+
const searchRegion = new Region(10, 20, 140, 100);
40+
const matchRequest = new MatchRequest(haystack, needlePath, searchRegion, minConfidence);
41+
const expectedResult = new Region(6, 11, needle.width, needle.height);
3842

3943
// WHEN
4044
const result = await SUT.findMatch(matchRequest);
4145

4246
// THEN
4347
expect(result.confidence).toBeGreaterThanOrEqual(minConfidence);
44-
expect(result.location).toEqual(searchRegion);
48+
expect(result.location).toEqual(expectedResult);
4549
});
4650

4751
it("findMatch should throw on invalid image paths", async () => {

0 commit comments

Comments
 (0)