Java: How to avoid false matches with "Screen.exists()"

Asked by Anson Liao

Hi All,
I would like to compare the expecting image whether exists the current screen, my java code below, expecting image, and part of current screen are below.
Screen s = new Screen();
if (s.exists("/expecting.png") != null)
System.out.println("Found.");
else
System.out.println("Image finding false.");

the result show "Found", the expecting image was found in the current screen image.
what others setting I need to setup?
and
how I can set up the image recognize sensitive value?

please check images I posted to github.
https://github.com/RaiMan/SikuliX-2014/issues/66

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
Best RaiMan (raimund-hocke) said :
#1

currently you have to use the similarity (expected minimum similarity score) with the Pattern class.

if (s.exists(new Pattern("/expecting.png").similar(value)) != null)

where value is a float value between 0f and 0.99f (which means exact match)

or
if (s.exists(new Pattern("/expecting.png").exact()) != null)
for exact match

BTW: your image filename /expecting.png means, you are storing your images in the root folder.
You should define an image folder somewhere, store your images there and use
ImagePath.setBundlePath(absolute path to your image folder)

and the you can use:
if (s.exists(new Pattern("expecting").exact()) != null)

for .png files.

looking at your question, I suppose, you not yet had a look at the docs:
http://sikulix-2014.readthedocs.org/en/latest/index.html
which gives you some insights on concepts and features.

the actual method signatures can be found in the javadocs (link on nightly build page)

Revision history for this message
Anson Liao (anson-o) said :
#2

Hi RainMan,
My java api version is 1.1.0-SNAPSHOT (the latest version towards final).
and found that under [s.exists(new Pattern("/expecting.png")], no method "similar" or "exact",
I have to using the latest beta version 1.1.0 nightly build?

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

please read carefully:
1. it is RaiMan (I am only responsible for Sikuli and not for the weather ;-)

2. similar and exact are Pattern methods and should be found there.

again:
to get all available information for version 1.1.0 development head start here
http://sikulix.com

Revision history for this message
Anson Liao (anson-o) said :
#4

Thanks RaiMan, that solved my question.

Revision history for this message
Anson Liao (anson-o) said :
#5

Hi RaiMan,
1.
apology for wrong typing your name.

2.
I know "everything about sikuli script", and I am newer in sikuli Java API.
as it is urgent have to find a tool to recognise the screen change in my test and integrate to Appium automation tool, so I am not enough time to read the instruction.

Revision history for this message
paulo doido silva (petronao) said :
#6

Thanks RaiMan, save my day.