Sikuli classpath UnsatisfiedLinkError no opencv_core with macosx intellij Junit

I have done previous searches trying to find an answer to this question, however my attempts have failed. I think the error is pretty simple, just not loading the classes.

I am running MacOSX 10 with intellij. I am using it with Junit Spring and Maven and Junit.

I followed maven dependencies found by mvnrepository.com - sikuli-api 1.2.0 so I thought if dependencies are added to pom then all files should be in my class? So I don't understand why it doesn't work?

This previous answer is close to mine - but its for windows im on mac. However, using maven I don't need to add it to the classpath? or am I missing something. This similar unanswered question also looks similar as my mac

Added POM dependencies

    <dependency>
        <groupId>org.sikuli</groupId>
        <artifactId>sikuli-api</artifactId>
        <version>1.2.0</version>
    </dependency>

    <dependency>
        <groupId>org.sikuli</groupId>
        <artifactId>sikuli-core</artifactId>
        <version>1.2.2</version>
    </dependency>

    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>14.0.1</version>
    </dependency>
    <dependency>
        <groupId>org.bytedeco</groupId>
        <artifactId>javacpp</artifactId>
        <version>0.9</version>
    </dependency>
    <dependency>
        <groupId>org.bytedeco.javacpp-presets</groupId>
        <artifactId>opencv</artifactId>
        <version>2.4.9-0.9</version>
        <classifier>macosx-x86_64</classifier>
    </dependency>
    <dependency>
        <groupId>org.piccolo2d</groupId>
        <artifactId>piccolo2d-core</artifactId>
        <version>1.3.1</version>
    </dependency>
    <dependency>
        <groupId>org.piccolo2d</groupId>
        <artifactId>piccolo2d-extras</artifactId>
        <version>1.3.1</version>
    </dependency>

      

My test

static {
    System.setProperty("platform.dependency", "macosx-x86_64");
    //System.setProperty("platform.dependency", "1");  // tried this also
}

@Test
public void testOne() throws Exception {

    File file = new File(getClass().getClassLoader().getResource("camera_icon.png").getFile());

    browse(new URL("http://code.google.com"));

    ScreenRegion s = new DesktopScreenRegion();
    Target target = new ColorImageTarget(file);

    // ** Fails here  **
    ScreenRegion r = s.find(target); 
    ....

      

Error - ClassLoader

I followed the debugger and it doesn't work in the classloader for open_core - see screenshot

enter image description here

Update

I've added a POM classifier for each of Samui's answer below. I also tried setting the system property . still getting the same error.

Also noticed the following error message - I tried to shorten it as much as possible.

Caused by: java.lang.UnsatisfiedLinkError: /private/var/folders/qp/.../libjniopencv_core.dylib: dlopen(/private/var/....../libjniopencv_core.dylib, 1): Library not loaded: @rpath/libopencv_core.2.4.dylib
  Referenced from: /private/var/.......libjniopencv_core.dylib
  Reason: no suitable image found.  Did find:
    /private/va.....77/./libopencv_core.2.4.dylib: malformed mach-o image: load command #12 length (0) too small in /private/var/fo......./libopencv_core.2.4.dylib  t java.lang.ClassLoader$NativeLibrary.load(Native Method)

      

+3


source to share


2 answers


For my job, I install opencv via homebrew. Open a terminal and enter the following.

brew tap homebrew/science

brew info opencv

brew install opencv



This allowed my POM to be much smaller

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>sikuliTest</groupId>
    <artifactId>sikuliTest</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>


    <dependency>
        <groupId>org.sikuli</groupId>
        <artifactId>sikuli-api</artifactId>
        <version>1.2.0</version>
    </dependency>

</dependencies>

</project>

      

Test

@Test
public void testOne() throws IOException {

    File file = new File(getClass().getClassLoader().getResource("image_to_click.jpeg").getFile());
    browse(new URL("http://code.google.com"));

    // click image that looks like image_to_click.jpeg
    ScreenRegion s = new DesktopScreenRegion(1);
    ScreenRegion s1 = s.find(new ImageTarget(file));
    Mouse mouse = new DesktopMouse();
    mouse.click(s1.getCenter());

    // take a screenshot and save it
    BufferedImage img = s.capture();
    File outputfile = new File("screenshot_image.jpg");
    ImageIO.write(img, "jpg", outputfile);
}

      

+1


source


The answer is mostly presented in the README.md file , but I'll cover it here. You will need to set either the system property platform.dependency

to the platform you want, for example macosx-x86_64

, or true

platform.dependencies

to get dependencies for all platforms. I'm not sure how we are supposed to install this using JUnit Spring (it should be in the docs), but even that doesn't work with SBT anyway, so to get around these cases we can add platform-specific dependencies manually. Since you are on Mac OS X and are interested in using OpenCV 2.4.9, adding this additional dependency to your file pom.xml

should work:



<dependency>
    <groupId>org.bytedeco.javacpp-presets</groupId>
    <artifactId>opencv</artifactId>
    <version>2.4.9-0.9</version>
    <classifier>macosx-x86_64</classifier>
</dependency>

      

+3


source







All Articles