OpenCV - studiofu/brain GitHub Wiki

OpenCV with Java

in windows platform, need to download the windows build, for example,

contain the jar file opencv-342.jar contain the native build dll files, opencv_java342.dll need to make sure the opencv_java342 dll dependency, use dumpbin in vs to search or use ldd to search in linux/cygwin

http://answers.opencv.org/question/195847/installation-problem-cant-find-dependent-libraries/

https://stackoverflow.com/questions/7378959/how-to-check-for-dll-dependency

usually, missing the mf.dll, mfplat.dll and mfreadwrite.dll


For normal java project, need to create the user library and then add the opencv-342.jar and then edit the build path of the native libraray location and point to the dll path

For the maven development and build, need to include the opencv artifact from the local repository

        <dependency>
            <groupId>opencv</groupId>
            <artifactId>opencv</artifactId>
            <version>342</version>
        </dependency>

To solve the maven testing missing dll link error during the build process, it's required to specify the dll

  • firstly add the dll to the project, for example, under libs/ folder
  • and then add the maven surefire plugin to specify the libs folder for native library.
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.20</version>
                <configuration>
                    <argLine>-Djava.library.path=${project.basedir}/libs/</argLine>
                </configuration>
            </plugin>

so the testing process is passed.

when executing the runnable jar, the dll must be placed correctly, same level as the jar file.

Sample Testing Code

package com.example.opencv;

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

import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class OpencvApplication implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(OpencvApplication.class, args);
    }

    @Override
    public void run(String...args) throws Exception {

        System.out.println("testing opencv: " + Core.VERSION);
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

        Mat m = Mat.eye(3, 3, CvType.CV_8UC1);

        System.out.println("m =" + m.dump());

    }
}
⚠️ **GitHub.com Fallback** ⚠️