Using JavaCV with Kotlin

前端 未结 3 1286
感情败类
感情败类 2021-01-23 11:06

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 modul

相关标签:
3条回答
  • 2021-01-23 11:56

    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.

    0 讨论(0)
  • 2021-01-23 12:04

    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:

    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.

    0 讨论(0)
  • 2021-01-23 12:06

    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.

    0 讨论(0)
提交回复
热议问题