Settings.MinSimilarity is not working with Java

Asked by Yann

Hello,
I'm trying to use Settings.MinSimilarity in Java code but it looks like the default value (0.7) is still used.

Settings.MinSimilarity = 0.9;
Pattern myPattern= new Pattern("file.png");
System.out.println("myPattern : "+myPattern.toString());
Match myMatch= screen.exists(new Pattern("file.png"));
System.out.println("myMatch : "+myMatch .toString());

My log :

myPattern : Pattern("/path/to/my/file.png").similar(0.7)
myMatch : Match[1634,80 35x35 score=0,74 target=center]

Any idea why ?

Regards,
Yann

Question information

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

per definition: each Pattern object has its own min similarity value, which is 0.7, if no similarity is given.

The Settings.minSmilarity only applies to plain images in
e.g. screen.find("image.png")

BTW: a Pattern is only needed, when either a special min similarity is needed for this image other than the default value of 0.7 or a target offset.

workaround:
Pattern p = new Pattern("image.png").similar(Settings.minSimilartity)

if you use this, these pattern objects will have what you want.

Revision history for this message
Yann (yann-jego) said :
#2

Strange, I though it was working in Python but not in Java. Why Settings.minSmilarity is not applied to every search ? I find it quite repetitive to write .similar(0.9) on all my click() and wait().

And does a search returns an Array of Match ordered by Score ? My Click() does not seems to always click on the best match. For a same picture.png Pattern (well displayed on the screen), sometime, it will click on a 0.8 match or 0.9 Match. Any workaround possible ?

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

--- Why Settings.minSmilarity is not applied to every search ? I find it quite repetitive to write .similar(0.9) on all my click() and wait().
As you can read in my above comment, it is in fact so as one would expect: with every click() and wait(), that uses a plain image (and not a Pattern object, which is only needed in rare cases), Settings.minSimilarity is used. So no need to "always write .similar().

--- My Click() does not seems to always click on the best match.
To understand you right:
On the same screenshot there are two similar images and one is matched with 0.9 and one with 0.8 and then the 0.8 match is clicked?
This should not be. A search should find the best match on the screen. If you think, this is not the case, send a screenshot and the respective image to my mail at https://launchpad.net/~raimund-hocke or store it somewhere in the net and post a link here.

Revision history for this message
Yann (yann-jego) said :
#4

Thanks RaiMan, that solved my question.

Revision history for this message
Shiva Golchi (shiva-golchi) said :
#5

I have also used SetMinSimilarity = 0.99, but it does not work. The script is still using default similarity (0.7) for all find operations.