An object of class Match represents the result of a successful find operation. It has the rectangle dimension of the image, that was used to search. It knows the point of its upper left corner on an existing monitor, where it was found.
Since class Match extends class Region, all methods of
Region can be used with a match object.
Creating a Match, Getting Attributes¶
It has the rectangle dimension of the image, that was used to search. It knows the point of its upper left corner on an existing monitor, where it was found. It knows the similarity it was found with and a click point to be used, if set by a pattern.
1# m is a reference to a match object, if found 2m = find() 3print m # message area: Match[10,0 30x22] score=1.00, target=center 4 5# m is a reference to a match object, if found 6m = find(Pattern().similar(0.5).targetOffset(100,0)) 7print m # message area: Match[10,0 30x22] score=1.00, target=(105,11)
For all other aspects, the features and attributes of class
Get the similarity score the image or pattern was found. The value is between 0 and 1.
Iterating over Matches after findAll()¶
A find operation
Region.findAll() returns an iterator object that can be
used to fetch all found matches as match objects one by one. A reference to the
iterator is stored in the respective
region and can be accessed using
Important to know:
- per definition, an iterator can be stepped through only once - it is empty afterwards
You can read more about the basics of operations with iterators from the description of
Finder class. To save contained matches for later use, you can convert them
1findAll() # find all matches 2mm = list(getLastMatches())
while: with default screen
1findAll() # find all matches 2mm = SCREEN.getLastMatches() 3while mm.hasNext(): # loop as long there is a first and more matches 4 print "found: ", mm.next() # access the next match in the row 5 6print mm.hasNext() # is False, because mm is empty now 7print mm.next() # is None, because mm is empty now 8print SCREEN.getLastMatches().hasNext() # is False also ;-)
with: with default screen
1with findAll() as mm: 2 while mm.hasNext(): # loop as long there is a first and more matches 3 print "found: ", mm.next() # access the next match 4# mm will be None afterwards (destroyed automatically) 5