Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am trying to follow the instructions for installing javaCV from here: https://code.google.com/p/javacv/. I ve already built opencv. Actually I locate the java folder with .jar file and .dll in opencv folder and I add them in the path of my project. When I am trying to run the SimpleSample.java I am receiving Error: Could not find or load main class FaceRecognition. Is there something else I ve got to follow in order to install javaCV? My simple Code
package simplesample;
/**
*
* #author snake
*/
import static com.googlecode.javacv.cpp.opencv_core.*;
import static com.googlecode.javacv.cpp.opencv_imgproc.*;
import static com.googlecode.javacv.cpp.opencv_highgui.*;
public class SimpleSample{
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
}
}
EDIT2: I add some jar files (javacv-windows-x86.jar, javacpp.jar, javacv.jar) and I finally got it running. But when I am trying to read a simple jpg image:
public static void main(String[] args) {
// TODO code application logic here
System.out.println("soul makosa");
IplImage image = cvLoadImage("ef.jpg");
if (image != null) {
cvSmooth(image, image, CV_GAUSSIAN, 3);
cvSaveImage("ef1.jpg", image);
cvReleaseImage(image);
}
}
I am reveiving the following errors:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no jniopencv_highgui in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1886)
at java.lang.Runtime.loadLibrary0(Runtime.java:849)
at java.lang.System.loadLibrary(System.java:1088)
at com.googlecode.javacpp.Loader.loadLibrary(Loader.java:711)
at com.googlecode.javacpp.Loader.load(Loader.java:586)
at com.googlecode.javacpp.Loader.load(Loader.java:540)
at com.googlecode.javacv.cpp.opencv_highgui.<clinit>(opencv_highgui.java:79)
at projectcv.ProjectCV.main(ProjectCV.java:28)
Caused by: java.lang.UnsatisfiedLinkError: C:\Documents and Settings\chrathan\Local Settings\Temp\javacpp101399456657827\jniopencv_highgui.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1965)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1890)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1851)
at java.lang.Runtime.load0(Runtime.java:795)
at java.lang.System.load(System.java:1062)
at com.googlecode.javacpp.Loader.loadLibrary(Loader.java:700)
... 4 more
Java Result: 1
I also add .dll file in properties->run->VM optimize as instructed here giving 'java.library.path' in netbeans for .dll/.so files. However I am still receiving the above message.
SOLVED:Ok my problems was due to the fact that I had to install specific version of javaCV. So for openCV version 2.4.6.1 I ve installed 0.6 java_CV and now works like a charm.
You need to add native class library path while adding opencv jar file into the project
Goto the buildpath>>libraries>>opencv >> click on expand and edit " native library location" to
C:/opencv/build/java/x86
for face FaceRecognition you need to add all jar files from that site
javacv-0.7-bin.zip
javacv-0.7-cppjars.zip
ffmg, etc....
it will work ....
Its working for me
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I am using Netbeans 7. I was provided with a class file (MT.class), that I need to test. I put it under build>classes.
I created a java class with main method. When I declare a new object using MT class, I get compiler error. Please let me know how to resolve this.
package mypack;
public class MyTest {
public static void main(String[] args) {
MyTest.avgTest();
}
public static void avgTest()
{
double res;
MT mt=new MT();
res=mt.avg(9,4);
System.out.println("The average is " + res);
}
}
If your .class file was compiled under a specific package hierarchy / dir structure, just create this structure under /libs . So if you class full name is foo.bar.MT then create /libs/foo/bar/ and put the .class file inside.
Then right click on your project in NetBeans > Properties > Libraries > Add JAR/Folder > then select the the libs folder from the above example.
Disclaimer Not native English speaker, feel free to edit if needed.
I'm having a similar issue that the one explained here :
java.lang.UnsatisfiedLinkError: Native Library XXX.so already loaded in another classloader
I'm trying to follow the answer of user2543253. But I really lacks of knowledge in Java and the context is a bit different.
Links
.dll already loaded in another classloader? Seems also related to this question.
https://github.com/PatternConsulting/opencv/issues/7 Similar.
https://cycling74.com/articles/mxj-class-loading Explains the class loader behavior of MXJ
Context
Edit : Not sure if that context is really important, it seems to be the same problem described in link 1.
I want to use OpenCV inside an Application called Max/MSP.
To give an idea, it looks like this :
Max/MSP allows user to assemble Patch by cabling some objects together that are called externals, most of them are coded in C but you can also create externals in Java. To do so you need to instantiate them through an object called "mxj". For example, if my Java class is called TestOpenCV, I will create a box and put "mxj TestOpenCV" inside.
OpenCV seems correctly implemented, for exemple, I can instantiate a Mat object and post its content to Max console.
Problems appears when I change the Java code of the mxj object. To update my object, I delete it and recreate it again. Then, the same issue that explained here appears...
Max console return this error message :
java.lang.UnsatisfiedLinkError: Native Library
C:\Windows\System32\opencv_java300.dll already loaded in another
classloader at java.lang.ClassLoader.loadLibrary1(Unknown Source) at
java.lang.ClassLoader.loadLibrary0(Unknown Source) at
java.lang.ClassLoader.loadLibrary(Unknown Source) at
java.lang.Runtime.loadLibrary0(Unknown Source) at
java.lang.System.loadLibrary(Unknown Source) at
OpenCVClassLoad.loadNativeLibrary(OpenCVClassLoad.java:5) at
TestOpenCV.(TestOpenCV.java:22) (mxj) unable to alloc instance
of TestOpenCV
What I tried
I tried to implement the answer of user2543253. He advices to create a tiny classes that import the native library and export it as a JAR. So I created a new Eclipse project added a source file to it
import org.opencv.core.Core;
public class OpenCVClassLoad {
public static void loadNativeLibrary() {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}
}
I added the openCV JAR to that project and exported it as a JAR.
Then I changed my code according to what user2543253 explained (there is more code,I kept the essential) :
import com.cycling74.max.*;
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.Scalar;
public class TestOpenCV extends MaxObject {
static {
// System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
OpenCVClassLoad.loadNativeLibrary();
}
public TestOpenCV(Atom[] args)
{
// ...
}
public void notifyDeleted()
{
// ...
}
public void bang() {
// Executed when I trig the little bang button you can see
Mat m = new Mat(5, 9, CvType.CV_8UC4, new Scalar(0));
post("OpenCV Mat: " + m);
Mat mr1 = m.row(1);
mr1.setTo(new Scalar(1));
Mat mc5 = m.col(3);
mc5.setTo(new Scalar(5));
post("OpenCV Mat data:\n" + m.dump());
}
}
Of course, but that's a bit weird, in order to build correctly that project I kept the JAR from OpenCV in the build path :
As you can see, I also added the tiny class in the project build path.
After all of theses modifications, the mxj object stille loads correctly the first time and the bang() method still works but the problem still there. In fact it doesn't change anything from the past situation : If I modify the Java code, delete the object in Max and create a new one, error appears...
Question
There is a lot of SO questions addressing the same type of prob but context is always different and its hard to figure out what to do, especially with my basic knowledge of Java.
A workaround should be to simply reuse that library already loaded, no ? but how to achieve this ? Because if I check the library has already being loaded, I do it using a Try / Catch, if I do nothing else. The externals acts like if the library had never been loaded...
How to reuse that native library ? (Of course, any alternative solution to this is welcome)
Just remove the second OpenCVClassLoad.loadNativeLibrary(); in your bang() method. In a plain Java application the code in a static block is only executed once.
Alternatively, you can specify the native library location in Eclipse instead of loading the library through Java source code.
This question already has answers here:
What is LD_LIBRARY_PATH and how to use it?
(6 answers)
Closed 8 years ago.
I am using Netutil class in my simple java app to show all network interfaces, the program code is as follow and the exception result after that. I am absolute beginer and your help is big time saver for me :)
package packet_experience;
import edu.huji.cs.netutils.NetUtilsException;
import edu.huji.cs.netutils.capture.*;
import java.io.IOException;
/**
*
* #author Pete
*/
public class Packet_Experience {
/**
* #param args the command line arguments
* #throws edu.huji.cs.netutils.NetUtilsException
* #throws java.io.IOException
*/
public static void main(String[] args) throws NetUtilsException, IOException {
JPCapInterface intArr[] = JPCap.getAllIntefacesNames();
for (JPCapInterface next : intArr)
{
System.out.println(next.toString());
}
}
run:
Exception in thread "main" java.lang.UnsatisfiedLinkError: edu.huji.cs.netutils.capture.impl.JPCapWraper.get_all_devices(Z)Ljava/lang/String;
at edu.huji.cs.netutils.capture.impl.JPCapWraper.get_all_devices(Native Method)
at edu.huji.cs.netutils.capture.impl.JPCapWraper.getAllInterfaces(JPCapWraper.java:299)
at edu.huji.cs.netutils.capture.JPCap.getAllIntefacesNames(JPCap.java:346)
at packet_experience.Packet_Experience.main(Packet_Experience.java:29)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
Update (Solution!):
My CPU is CORE i5 and having Win 7 Home Pre 64bit.
I tried JVM 32 and 64bit and changed System_PATH and java.library.path and copied all jar, dll, lib,... files there as well. Also I followed and performed recommendation I received on this page and I read in any other place ( as far as I could understand :) ).
At end I encountered with jnetpcap which has similar performance and I recommend it instead as works perfectly for me. You can find it at jnetpcap Homepage . Note that the same as Netutils you should adjust System_PATH and java.library.path and make sure you use JVM 32bit, otherwise you will definitely receive UnsatisfiedLinkError.
Have fun!
The error looks exactly like "You need a dll/so".
Try looking here:
NetUtils java library - how to make it work?
You will find the .dll somewhere on Your computer, just search Your windows dir.
I've seen lots of people asking similar questions to mine but their solutions aren't working for me. Here's what I've got:
I downloaded the latest OpenCV for Windows (2.4.9). I extracted this to C:\opencv-249
I then created a new Maven 3 project in IntelliJ. This works fine and I can run the compile/package goals, etc. I can execute and debug my program. This is all good.
Next, I tried to pull OpenCV into my test app and ended up with the following code:
package com.foo.OpenCVTest;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.CvType;
/**
* Created by rick on 5/7/2014.
*/
public class RobotCntrl {
static{ System.loadLibrary(Core.NATIVE_LIBRARY_NAME); }
static public void main(String args[]) {
System.out.println("In main!");
System.out.println("Core Lib: " + Core.NATIVE_LIBRARY_NAME);
Mat m = Mat.eye(3, 3, CvType.CV_8UC1);
System.out.println("m = " + m.dump());
}
}
I then added the local OpenCV to my pom.xml:
<dependency>
<groupId>org.opencv</groupId>
<artifactId>opencv</artifactId>
<version>2.4.9</version>
<systemPath>${java.home}/../../../../opencv-249/build/java/opencv-249.jar</systemPath>
<scope>system</scope>
</dependency>
And I added OpenCV as a project library:
And I modified the IntelliJ VM Options (Edit Configurations) to update the java.library.path to point to the OpenCV dlls:
When I run the application appears to load the opencv_java249.dll library just fine (it doesn't complain), but for the line:
Mat m = Mat.eye(3, 3, CvType.CV_8UC1);
It bombs out complaining that it can't find the underlying n_eye() native function:
In main!
Exception in thread "main" java.lang.UnsatisfiedLinkError: org.opencv.core.Mat.n_eye(III)J
Core Lib: opencv_java249
at org.opencv.core.Mat.n_eye(Native Method)
at org.opencv.core.Mat.eye(Mat.java:1467)
at com.aether.Robots.RobotCntrl.main(RobotCntrl.java:25)
Process finished with exit code 1
I'm at a loss now. It's loading the wrapper library but it can't call the dependent functions. For the previous questions on similar issues, it tends to be resolved when people update their java.library.path variable, but mine seems correct:
-Djava.library.path=C:\opencv-249\build\x64\vc10\bin;C:\opencv-249\build\java\x64
or people forget to call System.loadLibrary(), but that call is succeeding (as far as I can tell) for me.
Any ideas?
It's the first day of learning JavaCV for me. And this is the first test example which I use just to make sure that my setup is done correctly. Unfortunately I can't run the example and I barely understand the code and all dependencies so it's really hard for me to find out what is missing. Below I'll post my project setup and also the errors I get.
Also the example I use is from: http://ganeshtiwaridotcomdotnp.blogspot.com/2011/12/javacv-capture-save-flip-show-live.html
code
import static com.googlecode.javacv.cpp.opencv_core.cvFlip;
import static com.googlecode.javacv.cpp.opencv_highgui.cvSaveImage;
import com.googlecode.javacv.CanvasFrame;
import com.googlecode.javacv.FrameGrabber;
import com.googlecode.javacv.VideoInputFrameGrabber;
import com.googlecode.javacv.cpp.opencv_core.IplImage;
public class GrabberShow implements Runnable
{
//final int INTERVAL=1000;///you may use interval IplImage image;
CanvasFrame canvas = new CanvasFrame("Web Cam");
public GrabberShow()
{
canvas.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
}
#Override
public void run()
{
FrameGrabber grabber = new VideoInputFrameGrabber(0); // 1 for next camera
int i = 0;
try
{
grabber.start();
IplImage img;
while (true)
{
img = grabber.grab();
if (img != null)
{
cvFlip(img, img, 1);// l-r = 90_degrees_steps_anti_clockwise
cvSaveImage((i++) + "-aa.jpg", img); // show image on window
canvas.showImage(img);
}
//Thread.sleep(INTERVAL);
}
}
catch (Exception e)
{
}
}
}
I use Eclipse and it seems like all imports are there.
Here is a print screen of my project as it looks like in Eclipse:
So this is it for the setup. I try to get something out of this. When I right click on the project and try to Run it as Java Application the following windows is showing up:
You can see my choice at the top of the window. The I get an error window A Java Exception has occurred and here is part of the error I get in the console window:
Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Users\Xman\AppData\Local\Temp\javacpp4929678155627\jniopencv_core.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.load0(Unknown Source)
at java.lang.System.load(Unknown Source)
at com.googlecode.javacpp.Loader.loadLibrary(Loader.java:422)
at com.googlecode.javacpp.Loader.load(Loader.java:372)`
I've read the error, it seems like the problem is caused by missing libraries but I'm not sure, also I have followed the instructions (which weren't that many in fact) and from the comments below the example code it seems that it actually works. So I guess the problem is somewhere here - in my project, code, setup, but I can't find what I'm missing or doing wrong.
This error occurs when your opencv dll are not set in System path.
If you have extracted your opencv folder in C:\ directory then set your path as following
For 32 bit:
C:\opencv\build\x86\vc10\bin;C:\opencv\build\common\tbb\ia32\vc10\
For 64 bit:
C:\opencv\build\x64\vc10\bin;C:\opencv\build\common\tbb\intel64\vc10\
If you have extracted in different location then change the path accordingly.
In order to set path you can go to Control Panel > System Security > System > Advanced System Settings > Environment Variables. In System variable select path and click on Edit and insert above locations and restart windows.
you can find detailed instructions at http://opencvlover.blogspot.in/2012/04/javacv-setup-with-eclipse-on-windows-7.html
Download and install : Microsoft Visual C++ redistributable package (32-bit): vcredist_x86.exe