Skip to content

Commit

Permalink
MatchTemplateMask use alpha for mask pixels like FindImage does.
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Sep 22, 2024
1 parent f78d4b3 commit b971a0d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
Binary file added DocGen/images/shape.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DocGen/images/shape_background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions DocGen/source/tutorials/Image Finding.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#############
Image Finding
#############

Transparent pixels
==================

With :code:`FindImage` and :code:`FindTemplate` pixels that are fully transparent (being the pixels alpha value is 0) will be "skipped" when searched for.

For example with this image:

.. image:: ../../images/shape.png

With this as the target to search in:

.. image:: ../../images/shape_background.png

Would result with the image being found as transparent pixels would be ignored when searching.
1 change: 1 addition & 0 deletions DocGen/source/tutorials/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Tutorials

Random Numbers.rst
Color Finding.rst
Image Finding.rst
Sleep Until.rst
Targets.rst
Mouse & Keyboard.rst
Expand Down
2 changes: 1 addition & 1 deletion Source/simba.matchtemplate_helpers.pas
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function MaskFromTemplate(Templ: TIntegerMatrix): TRGBMatrix;
H := Templ.Height - 1;
for Y := 0 to H do
for X := 0 to W do
if (Templ[Y, X] and $FFFFFF) <> 0 then // Mask out alpha
if (PByte(@Templ[Y, X])^ <> 0) then // Alpha=0 is transparent. Data is flipped (TIntegerMatrix cast) so check first byte.
Result.R[Y, X] := 1;
end;

Expand Down

0 comments on commit b971a0d

Please sign in to comment.