I am running the following code snippet for OpenCV:
public static void main(String[] args){
System.out.println("Welcome to OpenCV " + Core.VERSION);
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Mat m = Mat.eye(3, 3, CvType.CV_8UC1);
System.out.println("m = " + m.dump());
}
I get this error:
Welcome to OpenCV 2.4.13.4
Exception in thread "main" java.lang.UnsatisfiedLinkError: org.opencv.core.Mat.n_eye(III)J
at org.opencv.core.Mat.n_eye(Native Method)
at org.opencv.core.Mat.eye(Mat.java:1468)
at HelloCV.main(HelloCV.java:29)
I have tried the following:
Putting the dll full path name on System.loadLibrary
Passing the dll path to JVM
Putting the dll file into the windows system32 folder
Putting the dll path name into eclipse opencv.jar config
It seems there was an issue with the following eclipse version:
Eclipse IDE for Java Developers
Version: Oxygen.1a Release (4.7.1a)
Build id: 20171005-1200
OS: Windows 10, v.10.0, x86_64 / win32
The below eclipse version works:
Eclipse SDK
Version: Neon (4.6)
Build id: I20160606-1100
Related
I would try to execute an example script based on Aparapi, on MAC OS. I'm using the last version of Eclipse, but when I execute DeviceInfo example to get all the available devices:
public class DeviceInfo {
public static void main(String[] args) {
KernelPreferences preferences = KernelManager.instance().getDefaultPreferences();
System.out.println("-- Devices in preferred order --");
for (Device device : preferences.getPreferredDevices(null)) {
System.out.println(device);
}
}
}
it generates the
java.lang.UnsatisfiedLinkError: com.amd.aparapi.OpenCLJNI.getPlatforms()Ljava/util/List"
Is there someone who can help me?
build the native assembly for Mac (x86_64) and add it into jniLibs; here's the source code.
java.lang.UnsatisfiedLinkError generally means, that it cannot find the native assembly.
Despite macOS Mojave 10.14.4 don't support directly OpenCL, I've executed Aparapi Framework.
I founded that the problem is the Aparapi Library. In particular, to resolve generated error I followed these steps:
Download this repository https://github.com/aparapi/aparapi for AMD Graphic Cards
Open the directory "com.amd.aparapi" and from terminal execute
ant -f build.xml
This command generates .jar file of this library
Add the generate jar to the project's classpath in Eclipse
Add the specific Aparapi library for your OS in:
<your-workspace-path>/<your-project>/src/main/resources/osx/
Before to execute the code, add the VM argument in "Run Configuration"
-Djava.library.path=<your-workspace-path>/<your-project>/src/main/resources/osx/
Execute your script!
So I would like to play with OpenCV little bit. My test project is in Java (OS is Debian Linux 8.4), and I have followed this tutorial to build OpenCV: https://opencv-java-tutorials.readthedocs.io/en/latest/01-installing-opencv-for-java.html
After fixing few issues, I was able to successfully build OpenCV jar and so file. There were no errors or warnings during the build. I have put opencv-400.jar and libopencv_java400.so into lib subfolder of my project. Added the jar file to build path in Eclipse, and put correct path to so file in Eclipse's Build Configurations.
My project has just a Main class which is a sample I found in OpenCV's sources, so nothing complicated:
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
public class Main {
public static void main(String[] args) {
System.out.println("Welcome to OpenCV " + Core.VERSION);
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Mat m = Mat.eye(3, 3, CvType.CV_8UC1);
System.out.println("m = " + m.dump());
}
}
It all looks that it should be working fine, but when I run the project, I see this exception:
Exception in thread "main" java.lang.UnsatisfiedLinkError: /home/firzen/ownCloud/develop/java/workspace/CVExperiments/lib/libopencv_java400.so: /home/firzen/ownCloud/develop/java/workspace/CVExperiments/lib/libopencv_java400.so: undefined symbol: _ZNK6google8protobuf8internal12MapFieldBase28SpaceUsedExcludingSelfNoLockEv
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1938)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1854)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at Main.main(Main.java:9)
And this part of exception is really making me worried:
/home/firzen/ownCloud/develop/java/workspace/CVExperiments/lib/libopencv_java400.so: undefined symbol: _ZNK6google8protobuf8internal12MapFieldBase28SpaceUsedExcludingSelfNoLockEv
It almost seems to me that there is something wrong with that libopencv_java400.so file. Am I right? Or do I need some another files to make it work? I have build OpenCV as Debug, so that so file has 135 MiB, but that shouldn't be a problem I think.
I will be thankful for any ideas!
That error means that your system does not have a suitable protobuf library installed. You might give sudo apt install libprotobuf10 a try, although I can't guarantee that will help.
Alternatively, you can also run ldd /home/firzen/ownCloud/develop/java/workspace/CVExperiments/lib/libopencv_java400.so, which will show you all libraries OpenCV tries to import - perhaps Protobuf has actually been built along with OpenCV, but is just not installed.
When constructing a new Mat instance in OpenCV 3.2, the program throws an UnsatisfiedLinkError. This happens both when invoking the Mat constructor directly, as well as when calling Imgcodecs.imread, which in turn throws an error on the following line:
Mat mats_mat = Converters.vector_Mat_to_Mat(mats);
The program is being run on a Mac running the latest version of macOS Sierra (10.12.3), and all available dylib files are located in the java.library.path directory. The file being read has been confirmed to exist. The stack trace reads (partially) as follows:
Exception in thread "main" java.lang.UnsatisfiedLinkError: org.opencv.imgcodecs.Imgcodecs.imread_1(Ljava/lang/String;)J
at org.opencv.imgcodecs.Imgcodecs.imread_1(Native Method)
at org.opencv.imgcodecs.Imgcodecs.imread(Imgcodecs.java:118)
The dylib files are loaded using the following code in main with no errors or warnings:
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
System.loadLibrary("opencv_imgproc.3.2.0");
System.loadLibrary("opencv_imgcodecs.3.2");
System.loadLibrary("opencv_videoio.3.2");
System.loadLibrary("opencv_highgui.3.2.0");
System.loadLibrary("opencv_flann.3.2");
System.loadLibrary("opencv_ml.3.2");
System.loadLibrary("opencv_features2d.3.2");
System.loadLibrary("opencv_calib3d.3.2");
System.loadLibrary("opencv_objdetect.3.2");
System.loadLibrary("opencv_photo.3.2");
System.loadLibrary("opencv_stitching.3.2");
System.loadLibrary("opencv_video.3.2.0");
System.loadLibrary("opencv_superres.3.2");
System.loadLibrary("opencv_shape.3.2");
System.loadLibrary("opencv_videostab.3.2");
The error is thrown when performing any of the following actions:
this(Imgcodecs.imread(filePath));
Mat mat = new Mat();
MatOfPoint matOfPoint = new MatOfPoint();
Printing out Core.NATIVE_LIBRARY_NAME on my machine (Ubuntu 16.04 w/ OpenCV 3.2 with Java and Python ports) gives me this:
opencv_java320
It seems to me that System.load requires a complete path whereas Core.NATIVE_LIBRARY_NAME only gives a partial name, not even including the extension! OpenCV Java has its default binary files path located at /usr/local/share/OpenCV/java. (At least for me or people who used the default settings when compiling) there you can find the library libopencv_java320.so which is the actual, correct native library you need to link to!
I'm trying to compile and run a simple example of Java code using OpenCV library, on Ubuntu 14.04 64bits, found in OpenCV's documentation:
Java OpenCV Documentation
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.CvType;
import org.opencv.core.Scalar;
class SimpleSample
{
static
{
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}
public static void main(String[] args)
{
System.out.println("Welcome to OpenCV " + Core.VERSION);
Mat m = new Mat(5, 10, CvType.CV_8UC1, new Scalar(0));
System.out.println("OpenCV Mat: " + m);
Mat mr1 = m.row(1);
mr1.setTo(new Scalar(1));
Mat mc5 = m.col(5);
mc5.setTo(new Scalar(5));
System.out.println("OpenCV Mat data:\n" + m.dump());
}
}
Since it is just a simple test, I really don't want to use any sophisticated building system. So I'm compiling with the following command:
javac -cp "/usr/share/OpenCV/java/opencv-248.jar" SimpleSample.java
However I'm unable to run the application, because when I call:
java SimpleSample
I face the following exception:
Exception in thread "main" java.lang.NoClassDefFoundError: org/opencv/core/Core
at SimpleSample.<clinit>(SimpleSample.java:10)
Caused by: java.lang.ClassNotFoundException: org.opencv.core.Core
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
Can someone help me running this application?
The opencv-248.jar is not on the CLASSPATH. You can run it as follows:
java -cp /usr/share/OpenCV/java/opencv-248.jar:. SimpleSample
Compile from the source and copy libopencv_java248.so into $JAVA_HOME/jre/lib/amb64/ directory. This platform specific file is not included in the jar file. Running the sample program without this file installed would get "java.lang.UnsatisfiedLinkError: no opencv_java248 in java.library.path" error. Also note that Apache Ant need to be installed for this platform specific file to be generated during compilation.
I managed to solve the problem.
In Ubuntu 14.04 64bit you can run the code from command line with the following command:
LD_LIBRARY_PATH=/usr/lib/jni/ java -cp /usr/share/OpenCV/java/opencv-248.jar:. SimpleSample
The OpenCV native binary library path (in my case libopencv_java343.dylib) can be defined with -D:
java -cp /opt/local/share/OpenCV/java/opencv-343.jar:. -Djava.library.path=/opt/local/share/OpenCV/java/ SimpleCV
I am just running sample sikuli script in Java on Eclipse & I am getting the following error
Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Program Files (x86)\Sikuli X\libs\VisionProxy.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1807)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1703)
at java.lang.Runtime.load0(Runtime.java:770)
at java.lang.System.load(System.java:1003)
at com.wapmx.nativeutils.jniloader.NativeLoader.loadLibrary(NativeLoader.java:44)
at org.sikuli.script.Finder.(Finder.java:33)
at org.sikuli.script.Region.doFind(Region.java:1034)
at org.sikuli.script.Region$RepeatableFind.run(Region.java:1237)
at org.sikuli.script.Region$Repeatable.repeat(Region.java:1208)
at org.sikuli.script.Region.exists(Region.java:539)
at com.testsikuli.SikuliTest.main(SikuliTest.java:25)
public class SikuliTest {
public static void main(String[] args) throws FindFailed {
System.setProperty("webdriver.ie.driver", "F:\\Softwares\\Selenium\\driver\\IEDriverServer.exe");
WebDriver driver;
driver = new InternetExplorerDriver();
driver.get("https://www.google.com");
driver.manage().timeouts().implicitlyWait(3000, TimeUnit.MILLISECONDS);
driver.manage().window().maximize();
Pattern userName = new Pattern("img/UserName.png");
Screen sr = new Screen();
sr.find(userName);
sr.type(Key.ENTER);
sr.type(Key.DELETE);
sr.type("test");
}
}
I'd followed lot of post & tired ..no luck..
My system environment details,
64bit Windows 7 SP1,
Java 6 (32bit) & eclipse JUNO (32bit)
Added JAVA_HOME = "C:\Program Files (x86)\Java\jdk1.6.0_45\" & path =
%JAVA_HOME%bin;%JAVA_HOME%jre\bin;
Also added SIKULI_HOME = "C:\Program Files (x86)\Sikuli X\" & path = %SIKULI_HOME%libs;
Was the Sikuli installation moved after it was installed at any time? If using Sikuli X, all required dependencies should be included in the installation.
Make sure your IDE isn't picking up any 64-bit JRE files from somewhere, as this will cause the exact error you are seeing.
This user seems to have had the same problem.
Maybe you can try this solution post: Link
Same error reported at the Sikuli buglist.
Java 7 does work for me though.
Link
Resolved. I had followed the same steps in the following post
Sikuli Windows 7 64 bit : Getting the VisionProxy.dll: Can not find dependent libraries
and modified/selected only "Append environment to native environment" & now its working fine. Thanks all.