Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make screen.find() more convenient on high-DPI devices #211

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/match-request.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export class MatchRequest {
public readonly searchRegion: Region,
public readonly confidence: number,
public readonly searchMultipleScales: boolean = true,
public readonly scaleNeedle: number = 1.0,
) {}
}
2 changes: 1 addition & 1 deletion lib/optionalsearchparameters.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ export class OptionalSearchParameters {
* @param confidence Optional confidence value to configure image match confidence
* @param searchMultipleScales Optional flag to indicate if the search should be conducted at different scales
*/
constructor(public searchRegion?: Region, public confidence?: number, public searchMultipleScales?: boolean) {}
constructor(public searchRegion?: Region, public confidence?: number, public searchMultipleScales?: boolean, public scaleNeedle?: number) {}
}
3 changes: 3 additions & 0 deletions lib/provider/opencv/template-matching-finder.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ export default class TemplateMatchingFinder implements FinderInterface {
`Failed to load ${matchRequest.pathToNeedle}, got empty image.`,
);
}
if (matchRequest.scaleNeedle !== 1.0)
needle = await scaleImage(needle, matchRequest.scaleNeedle);

const haystack = await loadHaystack(matchRequest);

if (debug) {
Expand Down
4 changes: 3 additions & 1 deletion lib/screen.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export class Screen {
const searchRegion =
(params && params.searchRegion) || await this.vision.screenSize();
const searchMultipleScales = (params && params.searchMultipleScales)
const scaleNeedle = (params && params.scaleNeedle) || 1.0;

const fullPathToNeedle = normalize(join(this.config.resourceDirectory, templateImageFilename));

Expand All @@ -97,7 +98,8 @@ export class Screen {
fullPathToNeedle,
searchRegion,
minMatch,
searchMultipleScales
searchMultipleScales,
scaleNeedle
);

return new Promise<Region>(async (resolve, reject) => {
Expand Down