1

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:

OpenCV Project Library Configuration

and for JavaCV:

JavaCV Project Library Configuration

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

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.

darthcrumpet
  • 343
  • 2
  • 5
  • 13

3 Answers3

0

Handling this error is no different in Kotlin from Java; you need to specify the path to the native libraries for opencv. By default on Windows it will look for the native libraries in whatever is set in your PATH environment variable.

You can also explicitly specify which directory to look for the native libraries by specifying the system property java.library.path (as indicated by the error message).

For example, you can add a run configuration like this: run config

Where ${PATH_TO_DYNAMIC_LIB} would be where ever the native lib opencv_imgproc320.dll is - I think in your case it would be C:/Users/ms/IdeaProjects/CVTest/opencv/build/java/x64.

JK Ly
  • 2,845
  • 2
  • 18
  • 13
  • Changing the library path in the VM options broke other libraries which were configured in intellij as they did not have the same library path and if specified, this is used instead of the path you specify for your libraries when configuring. – darthcrumpet Jul 05 '17 at 12:20
0

I was able to resolve this by leaving my VM options blank and adding all necessary OpenCV libraries as native library paths in my JavaCV library configuration.

darthcrumpet
  • 343
  • 2
  • 5
  • 13
0

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>

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

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.