I’ve tried linking to opencv using two unoffical maven packages then I recently just add the opencv-455.jar to a directory to forcefully include but I’m getting runtime linking issues
I’m able to successfully build but running gives me
Exception in thread "main" java.lang.UnsatisfiedLinkError: 'long org.opencv.core.Mat.n_Mat()'
at org.opencv.core.Mat.n_Mat(Native Method)
at org.opencv.core.Mat.<init>(Mat.java:23)
at org.opencv.core.MatOfInt.<init>(MatOfInt.java:35)
at frc.vision.MainKt.main(Main.kt:10)
at frc.vision.MainKt.main(Main.kt)
My main function looks like
import org.opencv.core.*
import org.opencv.videoio.*
fun main() = runBlocking {
println("Attempting a connection to the robot")
val client = RobotClient()
val ball_cam_props = MatOfInt(
Videoio.CAP_PROP_FRAME_WIDTH, 480,
Videoio.CAP_PROP_FRAME_HEIGHT, 640
)
...
}
Am I doing something wrong in my code or is by build.gradle.kts wrong?
ouuuucccchhhh ! this really hurts.
stick with a single version, remove all others. common sense, no ?
also, the jar only contains stubs / java wrappers. opencv is a c++ library, you need the corresponding opencv_java.dll/so, containing the real implementation code.
(and that’s what is missing here)
you also need to load that as the 1st thing in main() (or in a staticblock) similar to:
Should have specified, I wasn’t trying to link to multiple versions at the same time. When I’m trying to load opencv do I put that static block in Main.kt or do I have to put it in gradle?
I added System.loadLibrary(System.getProperty("java.library.path") + Core.NATIVE_LIBRARY_NAME + ".so") and I’m now getting
Exception in thread "main" java.lang.UnsatisfiedLinkError: Directory separator should not appear in library name: /usr/java/packages/lib:/usr/lib64:/lib64:/lib:/usr/libopencv_java455.so
at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:827)
at java.base/java.lang.System.loadLibrary(System.java:1873)
at frc.vision.MainKt.main(Main.kt:7)
at frc.vision.MainKt.main(Main.kt)
Even tried with a version of opencv compiled on my system and using the jar locally. Exception in thread "main" java.lang.UnsatisfiedLinkError: Can't load library: /usr/local/share/java/opencv4/opencv_java455.so
yea, i know. i found that part entirely frustrating, you got all my sympathy.
(unfortunately, i’m no more doing any java/kotlin dev, and i can help no more, sorry)