Skip to content

Commit 2fb2f1f

Browse files
committed
Merge branch 'develop'
2 parents 823e1cd + d681a9a commit 2fb2f1f

File tree

3 files changed

+35
-27
lines changed

3 files changed

+35
-27
lines changed

lib/provider/opencv/template-matching-finder.class.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,16 @@ export class TemplateMatchingFinder implements FinderInterface {
118118
}
119119

120120
public async findMatches(matchRequest: MatchRequest, debug: boolean = false): Promise<MatchResult[]> {
121-
const needle = await this.loadNeedle(
122-
await this.source.load(matchRequest.pathToNeedle)
123-
);
124-
if (needle.empty) {
121+
let needle;
122+
try {
123+
const needleInput = await this.source.load(matchRequest.pathToNeedle);
124+
needle = await this.loadNeedle(needleInput);
125+
} catch (e) {
126+
throw new Error(
127+
`Failed to load ${matchRequest.pathToNeedle}. Reason: '${e.message}'.`,
128+
);
129+
}
130+
if (!needle || needle.empty) {
125131
throw new Error(
126132
`Failed to load ${matchRequest.pathToNeedle}, got empty image.`,
127133
);

lib/screen.class.spec.ts

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { join } from "path";
2+
import { cwd } from "process";
13
import { VisionAdapter } from "./adapter/vision.adapter.class";
24
import { Image } from "./image.class";
35
import { LocationParameters } from "./locationparameters.class";
@@ -35,11 +37,11 @@ describe("Screen.", () => {
3537
const imagePath = "test/path/to/image.png";
3638
await expect(SUT.find(imagePath)).resolves.toEqual(matchResult.location);
3739
const matchRequest = new MatchRequest(
38-
expect.any(Image),
39-
imagePath,
40-
searchRegion,
41-
SUT.config.confidence,
42-
true);
40+
expect.any(Image),
41+
join(cwd(), imagePath),
42+
searchRegion,
43+
SUT.config.confidence,
44+
true);
4345
expect(visionAdapterMock.findOnScreenRegion).toHaveBeenCalledWith(matchRequest);
4446
});
4547

@@ -55,8 +57,8 @@ describe("Screen.", () => {
5557
const SUT = new Screen(visionAdapterMock);
5658
const imagePath = "test/path/to/image.png";
5759
await expect(SUT.find(imagePath))
58-
.rejects
59-
.toEqual(`No match for ${imagePath}. Required: ${SUT.config.confidence}, given: ${matchResult.confidence}`);
60+
.rejects
61+
.toEqual(`No match for ${imagePath}. Required: ${SUT.config.confidence}, given: ${matchResult.confidence}`);
6062
});
6163

6264
it("should override default confidence value with parameter.", async () => {
@@ -75,11 +77,11 @@ describe("Screen.", () => {
7577
const parameters = new LocationParameters(undefined, minMatch);
7678
await expect(SUT.find(imagePath, parameters)).resolves.toEqual(matchResult.location);
7779
const matchRequest = new MatchRequest(
78-
expect.any(Image),
79-
imagePath,
80-
searchRegion,
81-
minMatch,
82-
true);
80+
expect.any(Image),
81+
join(cwd(), imagePath),
82+
searchRegion,
83+
minMatch,
84+
true);
8385
expect(visionAdapterMock.findOnScreenRegion).toHaveBeenCalledWith(matchRequest);
8486
});
8587

@@ -99,11 +101,11 @@ describe("Screen.", () => {
99101
const parameters = new LocationParameters(customSearchRegion);
100102
await expect(SUT.find(imagePath, parameters)).resolves.toEqual(matchResult.location);
101103
const matchRequest = new MatchRequest(
102-
expect.any(Image),
103-
imagePath,
104-
customSearchRegion,
105-
SUT.config.confidence,
106-
true);
104+
expect.any(Image),
105+
join(cwd(), imagePath),
106+
customSearchRegion,
107+
SUT.config.confidence,
108+
true);
107109
expect(visionAdapterMock.findOnScreenRegion).toHaveBeenCalledWith(matchRequest);
108110
});
109111

@@ -124,11 +126,11 @@ describe("Screen.", () => {
124126
const parameters = new LocationParameters(customSearchRegion, minMatch);
125127
await expect(SUT.find(imagePath, parameters)).resolves.toEqual(matchResult.location);
126128
const matchRequest = new MatchRequest(
127-
expect.any(Image),
128-
imagePath,
129-
customSearchRegion,
130-
minMatch,
131-
true);
129+
expect.any(Image),
130+
join(cwd(), imagePath),
131+
customSearchRegion,
132+
minMatch,
133+
true);
132134
expect(visionAdapterMock.findOnScreenRegion).toHaveBeenCalledWith(matchRequest);
133135
});
134136
});

lib/screen.class.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Region } from "./region.class";
1010
export class Screen {
1111
public config = {
1212
confidence: 0.99,
13-
resourceDirectory: "./",
13+
resourceDirectory: cwd(),
1414
};
1515

1616
constructor(private vision: VisionAdapter) {

0 commit comments

Comments
 (0)