sikuli classpath UnsatisfiedLinkError没有opencv_core与macosx intellij Junit

时间:2015-07-02 14:23:02

标签: java opencv classpath sikuli unsatisfiedlinkerror

我之前的搜索试图找到答案,但到目前为止我的尝试失败了。我认为错误非常简单,只是没有加载类。

我正在使用intellij运行MacOSX 10。我正在使用它与Junit Spring和Maven& Junit。

我跟踪了发现mvnrepository.com - sikuli-api 1.2.0的maven依赖项,所以我在想如果将依赖项添加到pom中,那么所有文件都应该在我的类路径中?所以我不明白为什么它不起作用?

previous answer看起来很接近我的 - 但它是用于Mac上的Windows。但是通过使用maven,我不应该将它添加到类路径?或者我错过了什么。这个similar unanswered问题看起来类似于像我一样使用mac

添加了POM依赖关系

    <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>

我的测试

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); 
    ....

错误 - ClassLoader

我跟着调试器,它在open_core的类加载器上失败 - 见截图

enter image description here

更新

我在下面的Samuel回答中添加了POM分类器。我也试过setting the system property。仍然得到同样的错误。

还注意到以下错误 - 我试图尽可能地减少它。

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)

2 个答案:

答案 0 :(得分:3)

答案基本上在README.md file,但我会在这里拼写出来。您需要将platform.dependency系统属性设置为所需平台,例如macosx-x86_64true platform.dependencies,以获得所有平台的依赖关系。我不确定我们应该如何设置JUnit Spring(它应该在文档中),但即使这样也无法与SBT一起工作,所以为了解决这些问题,我们可以手动添加特定于平台的依赖项。由于您已在Mac OS X上运行并且对使用OpenCV 2.4.9感兴趣,因此将此附加依赖项添加到pom.xml文件应该有效:

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

答案 1 :(得分:1)

对于我的工作,我通过自制软件安装opencv。打开终端并输入以下内容。

brew tap homebrew/science

brew info opencv

brew install opencv

这让我的POM更小了

<?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
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);
}