Kotlin with OpenCV 4.10 on macOS terminal

asked 2019-05-15 08:00:33 -0500

Moso gravatar image

Hi!

I’m new to Kotlin (and also OpenCV) and can’t get a simple library test to work (either on macOS or linux).

The test code is:

package org.mytest

import org.opencv.core.Core
import org.opencv.core.CvType
import org.opencv.core.Mat

fun main(args: Array<String>) {
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME)

    val mat = Mat.eye(5, 5, CvType.CV_8UC1)
    println("mat = ${mat.dump()}")
}

After use:

kotlinc test-opencv.kt -classpath /usr/local/opt/opencv/share/java/opencv4/opencv-410.jar -include-runtime -d test-opencv.jar

I get the jar file.

But then, when I try:

java -Djava.library.path=/usr/local/opt/opencv/share/java/opencv4 -cp /usr/local/opt/opencv/share/java/opencv4/opencv-410.jar:. -jar test-opencv.jar

I got:

Exception in thread "main" java.lang.NoClassDefFoundError: org/opencv/core/Core
    at org.mytest.Test_opencvKt.main(test-opencv.kt:9)
Caused by: java.lang.ClassNotFoundException: org.opencv.core.Core
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 1 more

Any ideas?

edit retag flag offensive close merge delete