Issue with UnsatisfiedLinkError in OpenCV Java Binding on macOS

Hi,

I am working on a Java project using OpenCV to capture and process video streams. Below is the code I am using in my main method:

public static void main(String gg[]) {
    try {
        Loader.load(org.bytedeco.opencv.opencv_java.class);
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        String streamUrl = "https://thisis urlvideo_h1.m3u8";
        VideoCapture cap = new VideoCapture(streamUrl);
        if (!cap.isOpened()) {
            return;
        }
        Mat frame = new Mat();
        while (cap.read(frame)) {
            if (frame.empty()) {
                break;
            }
            // Process and annotate the frame
            System.out.println("====================================");
            System.out.println(frame);
            System.out.println("+++++++++++++++++++++++++++++++++++++");
        }
        cap.release();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

For dependencies, I am using the following Maven dependency:

<dependency>
    <groupId>org.bytedeco</groupId>
    <artifactId>opencv-platform</artifactId>
    <version>4.9.0-1.5.10</version>
</dependency>

Additionally, I installed OpenCV from the source with the following CMake flag:
-DBUILD_opencv_java=ON

However, when I run the code on my macOS machine, I encounter the following error:

java.lang.UnsatisfiedLinkError: 'long org.opencv.videoio.VideoCapture.VideoCapture_0()'

Could you please assist with resolving this UnsatisfiedLinkError issue? Is there anything specific to macOS I need to configure, or any steps I might have missed?

Thanks in advance!

3rdparty wrapper. no warranty.

so how can i fix this

OpenCV has Java bindings, which you can generate if you build OpenCV yourself. Building your own OpenCV is effort I wouldn’t recommend if you can avoid it.

I think the OpenCV organization bundles the Java build in the platform-specific releases. Old docs, for Windows, say something like

the opencv-4xx.jar file located at \opencv\build\java and the opencv_java4xx.dll library located at \opencv\build\java\x64 (for 64-bit systems)

MacOS is an environment entirely foreign to me, so you’ll need to browse OpenCV docs for those details. Some other website says to use homebrew… but that was advice for the OpenCV 3.x era, which is long past.

The bytedeco package is a build of OpenCV’s Java bindings by a third party, bytedeco. They provide the service to the Java community. They also appear to take care of Maven stuff in relation to this package.

You can try bytedeco’s community support. They’ll know best how to get their package working. I’d recommend searching for your error messages before posting. The answer might already be there.

You can also try searching their issues.