Lower pattern match within a loop on repeat

Asked by arminius

So I have a loop that's looking for an image that slowly changes over time, slowly changes back, so need it to look for them in sequence.

Here's an example of what I have with just two images, there's actually way more images in the real loop.

"print('1st loop')
while True:
    if exists(Pattern("1505851538186.png").targetOffset(-12,-37)):
        print('found 1st image at 1st loop')
        break

    elif exists(Pattern("1521782392359.png").targetOffset(-8,-33)):
        print('found 2nd image at 1st loop')
        break
    else:
        print('none of the images found at the 1st loop')
        #something that will lower the match by 1%
        continue
hover(getLastMatch())"

Exactly what the match percentage should be is getting hard to pin down, so would like it to start at 99% and after it hits tge bottom of the loop the percentage for all patterns gets lowered to 98% and so on.
I know how to program it to stop when the match gets to low, at that point I'll add another pattern.

I found this "https://answers.launchpad.net/sikuli/+question/256236"

So I assume the solution is to do with .similar, I've already been able to turn one images 99% into 98% right there on the same line, but that means it never looked for it at 99%

So not sure yet how to just lower the match at the bottom of the loop.

Sikuli version is 1.1.1
Windows 7

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
Manfred Hampl
Solved:
Last query:
Last reply:
Revision history for this message
TestMechanic (ndinev) said :
#1

I am not sure what is the question here.

I guess you are looking for 'similar' command: Pattern("some-element.png").similar(0.85)

Have in mind 2 more things:
-- There is a scan rate for images in Sikuli. It is 3 times/second by default
-- The exists command without parameter will look for image for relative short time - 3 seconds by default

If you can give more information what is the end goal we may be able to help you better.

Revision history for this message
Best Manfred Hampl (m-hampl) said :
#2

If I interpret your question correctly, then you are looking for something like

print('1st loop')
mySimilarity = 1.0
while True:
    if exists(Pattern("1505851538186.png").similar(mySimilarity)):
        print('found 1st image at 1st loop with similarity %f') % mySimilarity
        break
    elif exists(Pattern("1521782392359.png").similar(mySimilarity)):
        print('found 2nd image at 1st loop with similarity %f') % mySimilarity
        break
    else:
        print('none of the images found at the 1st loop')
        mySimilarity = mySimilarity - 0.05 # reduce by 5%
        continue
hover(getLastMatch())

Revision history for this message
arminius (arminius75) said :
#3

so sorry, I forgot to thank you for this, that's perfect, you even anticipated the need for the print part.

Revision history for this message
arminius (arminius75) said :
#4

Thanks Manfred Hampl, that solved my question.