1

I'm trying to use OpenCV's nonfree functionalities (like SIFT/SURF) in Java by compiling from source, but I'm encountering a DLL loading error in IntelliJ.

Here's my setup:

I'm using windows 11 24h2

Compilation Details: OpenCV Version: 4.12.0

CMake Configurations (the most important I think):

BUILD_SHARED_LIBS = ON
BUILD_JAVA = ON
BUILD_opencv_world = OFF
BUILD_opencv_java = ON
OPENCV_ENABLE_NONFREE = ON
OPENCV_EXTRA_MODULES_PATH = C:/opencv-build/opencv_contrib/modules

Compiler: Visual Studio 2022 (Release mode, x64)

Generated files:

  • opencv_java4120.dll (in build/lib/release)
  • opencv-4120.jar
  • some others .dll for the additional modules and some binary files

The compilation finished normally, I didn't have any errors.

I set the opencv version in pom.xml (I'm using maven)

<dependencies>
  <dependency>
    <groupId>org.opencv</groupId>
    <artifactId>opencv</artifactId>
    <version>4.12.0</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/lib/opencv-4120.jar</systemPath>
  </dependency>
</dependencies>

I've also added the dll path to IntelliJ's VM options

-Djava.library.path=.\src\main\resources 

I've tried with a simple code

package com.analisis;

import org.opencv.core.*;

public class Main {
  static {
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
  }

  public static void main(String[] args) {
    System.out.println("opencv version: " + Core.VERSION);
  }
}

This code works, but when I want to import a image using the Imgcodecs module I get this

Exception in thread "main" java.lang.UnsatisfiedLinkError: 
C:\Users\jesus\IdeaProjects\analisis_img\src\main\resources\opencv_java4120.dll: 
Error in a dynamic link library initialization routine. (DLL)
    at java.base/jdk.internal.loader.NativeLibraries.load(Native Method)
    ...

I Verified that:

The JAR and DLL versions match (both are from the same OpenCV build).

All required DLLs are in the same directory.

  • Why does the DLL fail to initialize despite correct paths?
  • Are there missing dependencies I should check?
  • Is there a precompiled Java-friendly version of OpenCV with nonfree modules?

The project is academic (patents aren't an issue).

I'm open to alternatives for using nonfree algorithms if compilation proves too complex.

3
  • is this AI-generated? there is no 4.12 yet, neither as a release nor as a tag. Commented Apr 21 at 9:57
  • not at all, when i cloned the repository of opencv i put 4.xx but, at this point i dont know which version is if you say so, maybe 4.1.2? Commented Apr 22 at 1:40
  • maybe they're very close to releasing 4.12 but that should leave signs elsewhere too. 4.11 is the current release. anyway, I don't use java more than once every couple of years, so I can't be of any help. Commented Apr 22 at 7:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.