将JavaCV与Kotlin一起使用 [英] Using JavaCV with Kotlin

查看:225
本文介绍了将JavaCV与Kotlin一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试在Kotlin中使用JavaCV启动项目.我正在使用IntelliJ Idea作为我的IDE.我正在使用JavaCV 1.3.2和OpenCV 3.20. 这是我针对OpenCV模块相关性的设置:

I'm currently attempting to start a project using JavaCV in Kotlin. I'm using IntelliJ Idea as my IDE. I'm using JavaCV 1.3.2 and OpenCV 3.20. This is my setup for the module's dependancies for OpenCV:

,对于JavaCV:

在依存关系上,我在javacv之前有opencv. 为了测试OpenCV是否存在并有效,我编写了以下内容进行测试.正如我可以加载库,并且版本号正确显示一样,我可以假设OpenCV实际上正在工作.

I have opencv before javacv in the dependancies. To test that OpenCV is present and valid, I wrote the below to test. As I can loadLibrary and the version number shows correctly I can assume that OpenCV is actually working.

import org.opencv.core.Core
import org.opencv.core.Mat
import org.opencv.core.CvType
import org.opencv.core.Scalar
import org.bytedeco.javacv.OpenCVFrameGrabber

fun main(args : Array<String>) {
    println("Test Built Successfully")
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME)
    println("Running OpenCV Version ${Core.VERSION}")
    val grabber = OpenCVFrameGrabber(1)
}

初始化抓取程序的行出现以下异常:

The line where we initialize the grabber rasies the following exception:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no jniopencv_core in java.library.path
Caused by: java.lang.UnsatisfiedLinkError: no opencv_imgproc320 in java.library.path

也许我在这里遗漏了一些东西,但是我遵循了JavaIT的Git存储库中README.md提供的说明.我没有看到其他人试图在StackOverflow上与Kotlin一起使用此库,尽管已经检查了一些有关使用Java引发相同异常的帖子.

Perhaps I am missing something here, but I have followed the instructions provided by the README.md in the Git repository for JavaCV. I haven't seen anybody else trying to use this library with Kotlin on StackOverflow, though have checked out some posts about the same exception being raised using java.

推荐答案

在MacOS上,您不需要安装本机库.在

on MacOS, you don't need to install a native library. On OpenCV3.41, as fetched from

<!-- https://mvnrepository.com/artifact/org.openpnp/opencv -->
    <dependency>
      <groupId>org.openpnp</groupId>
      <artifactId>opencv</artifactId>
      <version>3.4.2-1</version>
    </dependency>

我查看了库(jar tf ~/.m2/repository/org/openpnp/opencv/3.4.2-1/opencv-3.4.2.-1.jar),发现其中包含dll和其他内容:

I looked in the library (jar tf ~/.m2/repository/org/openpnp/opencv/3.4.2-1/opencv-3.4.2.-1.jar) and found dlls and whatnot in it:

jar tf *1.jar | grep nu
...
nu/pattern/opencv/osx/
nu/pattern/opencv/osx/x86_64/
nu/pattern/opencv/osx/x86_64/README.md
nu/pattern/opencv/osx/x86_64/cmake.log
nu/pattern/opencv/osx/x86_64/libopencv_java342.dylib
...

这使我想到了关于nu.pattern的StackOverflow问题展示了如何在代码中使用nu.pattern.

This led me to this StackOverflow question on nu.pattern which show how to use the nu.pattern in code.

static {
    nu.pattern.OpenCV.loadShared();
    System.loadLibrary(org.opencv.core.Core.NATIVE_LIBRARY_NAME);
}

此序言代码启用了以前无法运行的示例应用程序.

This prologue code enabled sample apps which used to fail as above to run.

这篇关于将JavaCV与Kotlin一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆