Using a list of stored captures

Asked by Ned

Hello again,

I have written a couple of functions to move through a scrollable list of of items, and capture an image of every entry on this list which is then appended to a list object called lCaptures.

What I am trying to figure out not is how I can compare that collection of stored images to look at another scrollable list on screen, find all possible matches, and when there are no more , to scroll down and try again until every stored image in my list is found.

Any suggestion on the most efficient way of achieving this?

Also, is i t it possible when using the Capture command to specify the similarity at which to take the image? For example I would like every image being put into lCaptures to be marked with a similarity rating of 99%

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

if time does not matter, then the easiest approach is to loop through your lCaptures and try to find each one successively in the other drop-down

dd = <the region of the other drop down>
ddSuccess = []

for image in lCaptures:
    if dd.exists(image):
        ddSuccess.append(dd.getLastMatch())
    else:
        ddSuccess.append(None)

after this run, ddSuccess contains the corresponding matches and None for the images not yet found.

now you have to scroll down the list and run this as often as needed, so we pack it in a def

def repeatSearch():
    n = 0
    for success in ddSuccess:
        if not success:
            if dd.exists(dd[n]):
                ddSuccess[n](dd.getLastMatch())
        n += 1

and make a loop

shouldRepeat = True
while shouldRepeat:
    scrollDownList() # a def that does it
    repeatSearch()
    shouldRepeat = decideAboutRepeat() # evaluate if we should stop and return false otherwise true

Revision history for this message
RaiMan (raimund-hocke) said :
#2

--- specify the similarity at which to take the image?
an image is captured as is with it's pixels

similarity gets relevant only at search time.
you either can specify a similarity to be used generally or with a single search

generally (used until changed again)
Settings.MinSimilarity = 0.99

per single search
use Pattern(image).similar(0.99) instead of image itself (or in case of 0.99: Pattern(image).exact() )

your above case:
    if dd.exists(Pattern(image).exact()):

Revision history for this message
Ned (nedleonard) said :
#3

Thanks that look helpful! I'm sure this will be what I need..

Just a few queries regarding the above.

In this section:

def repeatSearch():
    n = 0
    for success in ddSuccess:
        if not success: <--------- What does this do? Identifies a None Type?
            if dd.exists(dd[n]): <-------- this should be ddSuccess[n]?
                ddSuccess[n](dd.getLastMatch())

Revision history for this message
Ned (nedleonard) said :
#4

Also

ddSuccess[n](dd.getLastMatch())

This replaces the None Type with the last match? I hadn't seen that syntax before :)

Revision history for this message
RaiMan (raimund-hocke) said :
#5

--- if not success: <--------- What does this do? Identifies a None Type?
In Python in condition eval every variable containing None is taken as False and every variable containing a valid object ref is taken as True.
So this is True, when the entry was already found (contains a match)

--- if dd.exists(dd[n]): <-------- this should be ddSuccess[n]?
surely not (contains None ;-)
since we want to look for the existence of the image it must be:
 if dd.exists(lCaptures[n]): # sorry ;-)

--- ddSuccess[n](dd.getLastMatch())
LOL - did not see this before either …
ddSuccess[n] = dd.getLastMatch()

conclusion: you passed the test ;-)

Revision history for this message
RaiMan (raimund-hocke) said :
#6

BTW:
 ddSuccess[n](dd.getLastMatch())

would be valid, if ddSuccess[n] would contain the name of a function, that accepts one parameter.

Revision history for this message
Ned (nedleonard) said :
#7

Thank you :)

I will see how it goes!

Can you help with this problem?

Provide an answer of your own, or ask Ned for more information if necessary.

To post a message you must log in.