Error when I try to run Hello World OpenCV sample using java and eclipse

asked 2020-01-09 10:22:36 -0500

can anyone help me with opencv4 showing me a guide about how to configure opencv4 in eclipse?

I am using OS X and I prefer to use java instead of python.

I can see that there is an outdated guide, version 2.4.6, which is not longer present in release page

https://opencv.org/releases/

Downloading version 4 from that link does not solve my problem, because there is not any jar file. I can download it via mvnrepository.com

I can add the jar to eclipse, going to java, build path, user libraries, but, if I try to run the typical Hello world class

https://pastebin.com/vczZbaRt

I got this message:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv_java400 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867) at java.lang.Runtime.loadLibrary0(Runtime.java:870) at java.lang.System.loadLibrary(System.java:1122) at Hello.main(Hello.java:9)

The exact jar file that I am using.

I have compiled opencv4 sources from scratch, following this guide. I can run python samples in my osx environment without a problem, but i would like to use java code instead of python.

Please, what do i have to do to have a fully functional eclipse environment to work with opencv 4 using java?

edit retag flag offensive close merge delete

Comments

Opencv is a c++ computer vision library. There are some wrappers available for other languages too (python, java). But they will have to make c++ calls to do their job.

In your case - just adding the jar to classpath is not enough. The dll for the c++ calls(via jni) must also be in the java.library.path. To make it short - just follow this tutorial

holger gravatar imageholger ( 2020-01-09 13:47:29 -0500 )edit

Hi Holger, thanks for the assistante. I already read the the tutorial, but is it based on a deprecated version, which is no longer present in the repository. The tutorial is based in v 2.4.6. Actual version is 4.2. There are no jars present, just cpp source files. Is it possible to read an updated tutorial? the folders described in v 2.4.6 are not longer located where the tutorial says, so i am confused.

aironman gravatar imageaironman ( 2020-01-09 14:14:40 -0500 )edit

The tutorial is for 3.4.2 using 2.4.6 screenshots. Yes its outdated - but the way things are done (adding jars + native library location ) is still the same(only different version numbers) - even on the newest version. So please don't be confused.

"There are no jars present, just cpp source files." Then you don't have a binary/prebuild version but only the source code or your version was build without the java wrapper or you looking in the wrong location. Anyways, you either build opencv per hand or get some prebuild binaries for your system with java support. Then you follow the tutorial.

holger gravatar imageholger ( 2020-01-10 03:57:48 -0500 )edit

Please, could you send me to the right official prebuilt location?

aironman gravatar imageaironman ( 2020-01-10 12:45:40 -0500 )edit