ScaleParam

Settings for finding template images inside a Region. Pass this object as the Region's scale_param; these settings do not change the region's coordinates.

Syntax

ScaleParam(grayscale=True, auto_scale=False, cache_scale=True, template_scale="SHORT_EDGE", fast_matching=False)

Constructor parameters

NameDescription
grayscaleBoolean
**Applies to templates**. Convert template matching to grayscale.
Optional · Positional or named
Default: True
auto_scaleBoolean
Try nearby template sizes after applying template_scale. The range adapts to screen size/density and may extend from 0.70x to 1.30x. Has no effect with template_scale="NONE".
Optional · Positional or named
Default: False
cache_scaleBoolean
Remember a successful auto_scale size for later searches with the same settings. Applies only when auto_scale=True.
Optional · Positional or named
Default: True
template_scaleString
How to resize the template for this device: SHORT_EDGE uses the shorter screen edge; LONG_EDGE the longer edge; DPI the pixel density; SMALLEST_WIDTH_DP the shorter edge in dp. NONE keeps the image size unchanged.
Optional · Positional or named
Default: SHORT_EDGE
fast_matchingBoolean
Downsample both the Region image and template to two thirds before matching. This is faster but may slightly reduce accuracy, especially for small icons.
Optional · Positional or named
Default: False

Returns

Example

# Configure matching preprocessing on this Region
settings = ScaleParam(grayscale=True, fast_matching=True)
region = Region(100, 200, 300, 400, scale_param=settings)
print(region.find("start", timeout=0).found)

Fields

NameDescription
grayscaleBoolean
**Applies to templates**. Convert screenshot/template to grayscale before template matching.
Default: True
auto_scaleBoolean
Try nearby template sizes after applying template_scale. The range adapts to screen size/density and may extend from 0.70x to 1.30x. Has no effect with template_scale="NONE".
Default: False
cache_scaleBoolean
Remember a successful auto_scale size for later searches with the same settings. Applies only when auto_scale=True.
Default: True
template_scaleString
How to resize the template for this device: SHORT_EDGE uses the shorter screen edge; LONG_EDGE the longer edge; DPI the pixel density; SMALLEST_WIDTH_DP the shorter edge in dp. NONE keeps the image size unchanged.
Default: SHORT_EDGE
fast_matchingBoolean
Downsample both the Region image and template to two thirds before matching. This is faster but may slightly reduce accuracy, especially for small icons.
Default: False
Field example
param = ScaleParam(auto_scale=True, template_scale="LONG_EDGE", fast_matching=True)
param.cache_scale = False
template_mode = param.template_scale
Constructor example
param = ScaleParam(grayscale=True, auto_scale=True, cache_scale=True, template_scale="LONG_EDGE", fast_matching=True)
quick = ScaleParam(False, True, True, "LONG_EDGE", True)