sikuli classpath UnsatisfiedLinkError no opencv_core with macosx intellij Junit

sikuli classpath UnsatisfiedLinkError no opencv_core with macosx intellij Junit

我以前曾进行过搜索,试图找到这个问题的答案,但到目前为止我的尝试都失败了。我认为错误很简单,只是没有加载 classes。

我是 运行 MacOSX 10 with intellij。我将它与 Junit Spring 和 Maven & Junit 一起使用。

我按照找到的 Maven 依赖关系 mvnrepository.com - sikuli-api 1.2.0 所以我在想如果将依赖关系添加到 pom 那么所有文件都应该在我的 class 路径中?所以我不明白为什么它不起作用?

这个 previous answer looks close to mine - but its for windows im on a mac. However by using maven I should not need to add it to the class path?? or am I missing something. This 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); 
    ....

错误 - 类加载器

我跟踪了调试器,它在 open_core 的 class 加载器上失败了——见屏幕截图

更新

我根据下面的 Samuel 回答添加了 POM classifier。我也试过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)

答案基本在README.md file中,但我会在这里拼写出来。您需要将 platform.dependency 系统 属性 设置为所需平台,例如 macosx-x86_64,或 true 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>

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

brew tap homebrew/science

酿造信息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);
}