← Back to team overview

sikuli-driver team mailing list archive

[Question #699617]: Sikuli doesn't find image on screen but does in image explorer.

 

New question #699617 on SikuliX:
https://answers.launchpad.net/sikuli/+question/699617

Hello !

You can also find my question on stackoverflow : https://stackoverflow.com/questions/69913012/sikuli-on-java-does-not-recognize-images

I am new to Sikuli, and wanted to use it to automatize some tasks on my computer. I use Java in my every-day job, so I am using Sikuli in a java program (+maven + eclipse). I am using windows 10, no VM, two monitors (I tried to unplug the 2nd one, but it doesn't fix the problem).

The maven dependency I use is the following : 

<dependency>
    <groupId>com.sikulix</groupId>
    <artifactId>sikulixapi</artifactId>
    <version>2.0.5</version>
</dependency>

I tried to do some simple stuff. I did a few screenshots of parts of my screen using windows' screenshot tool, and wanted sikuli to hover it. It works quite fine for one image, but not at all for the others. It seems that the bigger the image the better it works as I did not have success for any small images. The one working is a screen of a whole window (reduced to ~1/4 of my screen). I also tried to find a button inside this window, to find the windows logo on bottom left, to find a screen of my package explorer, but none work correctly.

I played with similar() using various values, but it didn't improve the results. In some cases (button inside the window) it did find a result for some low similar value, but it was another button. The weird part is : its finding this other button which is bright blue, while the one i'm looking for is purple.

My pc background never changes, I did some screen.highlight() and its looking at the correct screen (dual screen). It's not an issue with the path to images (already solved this one).

Do you have any idea of what I could try ? I have read about people having different success rate depending on whether they were using Sikuli IDE or another IDE. So maybe I could give sikuli IDE a try.

The code I'm using to test :

public class CleanTest {
    
    static Screen screen = new Screen();

    public static void main(String[] args) throws FindFailed, AWTException, IOException, InterruptedException {
        String pathYourSystem = System.getProperty("user.dir") + "\\";
        Pattern pLauncher = new Pattern(pathYourSystem+"img\\full_launcher.PNG").similar(0.9d);
        Desktop.getDesktop().open(new File("path_to_an_exe_opening_a_launcher"));
        screen.wait(pLauncher, 300);
        screen.mouseMove();
        System.out.println("launcher found");
    }

}

It works with the "full launcher" image, but it doesn't find a sub-part of the launcher (a button). I tried to make some code to test if there was some threshold for the similar parameter :

        double similarValue = 1d;
        Pattern pLauncher = new Pattern(pathYourSystem+"img\\the_button.PNG").similar(similarValue);
        Desktop.getDesktop().open(new File("path_to_an_exe_opening_a_launcher"));
        
        while(!screen.has(pLauncher)) {
            similarValue-=0.1;
            pLauncher = pLauncher.similar(similarValue);
        }
        System.out.println(similarValue);
        screen.mouseMove();



I also did a bit more testing: if i take a screenshot of a part of my IDE then run a simple 

while(!screen.has(<myScreenPath>)){}
 screen.getLastMatch().highlight(2);

It doesn't highlight anything. That's very weird. I tried to unplug my second monitor and to use different tools to screenshot, without success.
What I did: take a screenshot of a constant part of my screen (menu icons of eclipse, for example). Save it. Launch the previous code. Nothing get highlighted. Then without stopping the execution, I open the image file. It does find it and highlight it.



Thanks for your help.

-- 
You received this question notification because your team Sikuli Drivers
is an answer contact for SikuliX.