I am trying to build my Java project with maven and opencv on Centos 8. With try some way to fix, i can build it as a .jar
file to run API. But when my service call lib from opencv, it throws the following error: java.lang.UnsatisfiedLinkError: 'long org.opencv.core.Mat.n_Mat()'
.
My reference to install opencv in centos 8: https://my.oschina.net/u/3568600/blog/4553084
This is my step:
- Install cmake and ant.
- Download:
wget https://github.com/opencv/opencv/archive/4.4.0.zip
and unzip it - Run command:
cd opencv
mkdir build
cd build
- Run cmake:
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -DBUILD_TESTS=OFF ..
make
sudo make install
Outout after run this step:
Move lib:cp -r /usr/local/share/java/opencv4/libopencv_java440.so /usr/lib
- Check version:
ldconfig -v | grep opencv
Here my ouput:
Here my java code to load core native lib:
public static void main(String[] args) {
System.load("/user/lib/libopencv_java440.so");
SpringApplication.run(MyApp.class, args);
}
My process throw error:
public static Mat BufferedImage2Mat(BufferedImage image) throws IOException {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ImageIO.write(image, "png", byteArrayOutputStream);
byteArrayOutputStream.flush();
return Imgcodecs.imdecode(new MatOfByte(byteArrayOutputStream.toByteArray()), Imgcodecs.IMREAD_UNCHANGED); // Throw in this line
}
What do you recommend I do next?
Note: my code running normal in local (Windows) with change libopencv_java440.so
to opencv_java440.dll
and add opencv-440.jar
to class path in eclipse.
I found simple way to resolve it.
In pom.xml add dependency:
Register opencv-440.jar to maven by command:
mvn install:install-file -Dfile=/path/opencv-440.jar -DgroupId=org.opencv -DartifactId=opencv-440 -Dversion=4.4.0 -Dpackaging=jar