exists() finds patterns that are not there

Asked by Elisabeth Svensson

Hi!

I've been working on a script that opens the calculator, presses a few buttons and checks that the answer is correct (for tutorial).
The problem is that exists() doesn't seem to tell the difference between similar patterns.
The script looks like this:

def testCalc(self):
 click("image-of-5-button")
 display = "region-of-calc-display"
 if display.exists("image-of-display-displaying-15"):
  print("Something is wrong"); return False
 else:
  print("It's all good."); return True

This return "False", but works is I compare, say "3" to "15" instead of "5" to "15"

It works if I change the if-condition to:

        if display.exists("image-of-display-displaying-15").getScore() > 0.8:

However, then a new problem arises, should exists() ever return "None".

Do you have any ideas on how to solve this? :) Have I been using exists() wrong?
//Elisabeth

Question information

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

if I understand right, what you are doing.

The expected content of the display is 5 after pressing 5, so you should compare against the appropriate image (or does the display already contain a 1 - I do not know).

def testCalc(self):
 click("image-of-5-button")
 display = "region-of-calc-display"
 if display.exists(Pattern("image-of-display-displaying-5").similar(0.9)):
  print("It's all good."); return True
 else:
  print("Something is wrong"); return False

The key factor you seem to miss is "minimum similarity" (see the changed exists() above).

The default similarity is 0.7, which might lead to wrong results. If you expect something to be really equal, the similarity should be at least 0.9 or more ( in most cases it will be 1.0).

This has to be given to the find() operation using a Pattern object:

exists(Pattern("image-of-display-displaying-5").similar(0.9)

means, that you expect a found image to be equal to your probe, if the similarity of a match is at least 0.9 (the value you get from the match using getScore()), otherwise the find fails.

You may have a look at the docs.

Revision history for this message
Elisabeth Svensson (elisv123) said :
#2

Gah, I didn't even think of it that way.
This was just the suggestion I was looking for. Thank you.