Ask Your Question

Build Java wrappers OpenCV 3.3.0 with contrib

asked 2017-08-08 12:30:56 -0500

phillity gravatar image

updated 2017-11-12 18:28:23 -0500

Can someone point me to a guide to build Java wrappers OpenCV 3.3.0 (or 3.2.0) with contrib modules? I am using Windows 10. I have run into several problems trying to follow online guides :( If someone knows of a good guide to accomplish the build, I would be very grateful if you shared it with meeee

EDIT: I ended up being able to build 3.2.0 but now have run into another problem.

After the build, I received a opencv_java320.jar and a libopencv_java320.dll (and a opencv_ffmpeg320.dll). I am trying to use Eclipse. I made a new User Library pointing to the opencv_java320.jar. I am unsure where the Native Library Location should point to. It seems that it should be pointing to a opencv_java320.dll file, but I got no such file from my build. I have no jars or dlls other than opencv_java320.jar and a libopencv_java320.dll (and a opencv_ffmpeg320.dll). Is there some way to resolve this issue or was my build unsuccessful?

edit retag flag offensive close merge delete



did you already run cmake? show us cmake's generating output

sturkmen gravatar imagesturkmen ( 2017-08-08 14:39:45 -0500 )edit

cmake output looks OK. i can't say anything about MinGW because i used MS Visual Studio to compile. i recommend you to use MS Visual Studio

sturkmen gravatar imagesturkmen ( 2017-08-09 13:11:08 -0500 )edit

"After the build, I received a opencv_java320.jar and a libopencv_java320.dll" try to rename libopencv_java320.dll -> opencv_java320.dll

sturkmen gravatar imagesturkmen ( 2017-08-09 18:19:08 -0500 )edit

After renaming I can successfully System.loadLibrary(Core.NATIVE_LIBRARY_NAME), but then I receive an unsatisfied link error on the first line of code using OpenCV: Exception in thread "main" java.lang.UnsatisfiedLinkError: org.opencv.core.Mat.n_Mat()J

phillity gravatar imagephillity ( 2017-08-09 18:29:18 -0500 )edit

try the files someone shared

sturkmen gravatar imagesturkmen ( 2017-08-09 18:38:12 -0500 )edit

show your java code also

sturkmen gravatar imagesturkmen ( 2017-08-09 18:42:24 -0500 )edit


import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
public class Hello
   public static void main( String[] args )
      System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
      Mat mat = Mat.eye( 3, 3, CvType.CV_8UC1 );
      System.out.println( "mat = " + mat.dump() );
sturkmen gravatar imagesturkmen ( 2017-08-09 18:56:07 -0500 )edit

I was using a 32 bit jdk so I changed to a 64 bit one, now I am getting:

Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\OpenCV-
3.2.0\build\install\java\opencv_java320.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(
at java.lang.ClassLoader.loadLibrary(
at java.lang.Runtime.loadLibrary0(
at java.lang.System.loadLibrary(
at BIFtest.main(
ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2
JDWP exit error AGENT_ERROR_NO_JNI_ENV(183):  [util.c:840]
phillity gravatar imagephillity ( 2017-08-09 18:56:37 -0500 )edit

sorry, maybe i disguided you. again i say. if you use MS Visual Studio probably you will solve all problems.

sturkmen gravatar imagesturkmen ( 2017-08-09 19:00:18 -0500 )edit

otherwise you can download compiled dlls from

sturkmen gravatar imagesturkmen ( 2017-08-09 19:01:55 -0500 )edit

0 answers

Sort by ยป oldest newest most voted

answered 2017-11-12 18:28:10 -0500

phillity gravatar image

Hello everyone! I had to take some time off OpenCV, but, after returning, I was able to successfully build OpenCV 3.3.1 with contrib for Java!! Big thanks to sturkmen!!! As sturkmen suggested, Visual Studio was able to resolve my issues.

If you are trying to build OpenCV with contrib for Java I suggest:

First following this guide but disregard the MinGW section/steps:

Then use visual studio and follow the steps outlined here:

Good luck Java friends!

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-08-08 12:30:56 -0500

Seen: 2,421 times

Last updated: Nov 12 '17