ConfusingCalc
ConfusingCalc

Reputation: 133

Can't get Sikuli to recognize images

I'll start by saying that I'm using Netbeans and Java (JDK 8 x64). I've installed Sikuli selecting the option to install the Sikuli IDE as well as the option for it to work with other IDEs.

When using the Sikuli IDE it finds the images fine without any issue. When I copy that image into my project resource folder and try to find it via my project in Netbeans, it won't find it.

I believe the version that I'm using is 1.0.1 for Sikuli.

Here is the test code I am trying:

public class TestSikuli {

    public static void main(String[] args) {
        Screen s = new Screen();
        try{
            s.click("resources/startBtn.png");
        } catch(FindFailed e){
            e.printStackTrace();
        }
    }

}

I'm assuming it doesn't know where resources/startBtn.png is. So I've tried using

ImageLocator.addImagePath(System.getProperty("user.dir" + File.separator + "resources")

However, when printing out the contents of ImageLocator.getImagePath() it doesn't appear to ever add the image path.

My question seems to be, what are the necessary steps to get Sikuli to work in Netbeans for Java. I've stumbled across some setup steps for Jython, but I wasn't sure if those were necessary for Java as it seems a bit convoluted.

Do I need to add something to my PATH? Do I need to add another environment variable? All I've done up to this point is use the installer and then add the jar to my Netbeans Project.

Any and all advice will be appreciated. I've been searching for a proper answer to this for a few days and figured I would just resort to asking StackOverflow.

edit: Added Eclipse to the tags due to the assumption that the process of integrating Sikuli should be relatively similar for each IDE.

Upvotes: 0

Views: 1548

Answers (2)

Tenzin
Tenzin

Reputation: 2505

This is a little bit out of field here, since I don't really use Java with my Sikuli. But since I build a batch file to run my Sikuli program maybe you do have a path wrong.

When you start the Sikuli IDE and make a Hello World program. Then it makes a map with .sikuli. In those are all the files it needs. I think if you open this with another IDE you need all those documents in that place as the Hello World program made it.

Another thing is that when installing Sikuli, it makes directories/files where you installed it. I learned it is quite picky about from where you execute it from. Maybe that could be the case here too?

Maybe you should see if the click() is recognized as a command anyway.

Upvotes: 0

asemahle
asemahle

Reputation: 20805

If the addImagePath() function doesn't appear to be working you could always try modifying the image path yourself. From the 1.0.1 docs:

Note: Behind the scenes this list is maintained in the java property store with the key SIKULI_IMAGE_PATH. This can be preset when starting the JVM using the environment variable SIKULI_IMAGE_PATH and can be accessed at runtime using the approach as mentioned under Accessing Settings - Java level. Be aware, that this is one string, where the different entries are separated with a colon ( : ). [source]

Try something like:

java.lang.System.getProperty("SIKULI_IMAGE_PATH", "user.dir" + File.separator + "resources");

Alternatively, you could store your images outside of the jar and try setBundlePath() instead.

NOTE: I use Jython and Sikuli 1.1.0, so I haven't tested the provided code.

Upvotes: 1

Related Questions