HowTo use class Finder in Java

Asked by Yi Chai

I am using Sikulix.jar to search images in my project. My code is as follows:

Finder f;
Match m;
Points2D coords = new Point2D.Double(-1, -1);
try {
    f = new Finder(new Pattern(ImageIO.read(new File("my_large_image.png")).similar(0.7f)));
    f.find(ImageIO.read("my_sub_image.png"));
    if (f.hasNext()) {
        m = f.next();
        coords.setLocation(m.getTarget().getX(), m.getTarget().getY());
    }
} catch (IOException e) {}
The image to be found is just a part of the large image. I set However the coords always returns (-1, -1). But it is working perfectly when I use Screen to click target image. Any helps about the implementation? Thank you.

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

This should not work at all:
new Finder(new Pattern(...))
... since this constructor is not defined.

this is how it should work:
f = new Finder("my_large_image.png");
f.find("my_sub_image.png");
if (f.hasNext()) {
    Sytem.out.println(f.next())
}

see the docs and the Java API docs (http://sikulix.com)

Revision history for this message
Yi Chai (rongshuxiacy) said :
#2

Sorry, my mistake. The code I was using is just like what you provided. But I think I found the answer. It is due to the image resolution. The large image(Android device) and the sub-image(Desktop screenshot) were taken by different screenshot tools. I wonder if there is a way to find image under different resolution situations? Thank you so much.

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

read this, to understand your problem:
http://sikulix-2014.readthedocs.io/en/latest/basicinfo.html#sikulix-how-does-it-find-images-on-the-screen

conclusion: different resolution <=> different image

Can you help with this problem?

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

To post a message you must log in.