I need capture a video stream from my USB webcam, for this i use Opencv 2.4.6 for developing in Java. I follow the steps listed in here
I add the "C:\opencv\build\java\x64" dir to my System PATH and include the "opencv-246.jar" file into my libraries on ECLIPSE. When y run the explame
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.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Mat m = Mat.eye(3, 3, CvType.CV_8UC1);
System.out.println("m = " + m.dump());
}
}
i get
m = [1, 0, 0;
0, 1, 0;
0, 0, 1]
OK =)
but when i run
import org.opencv.highgui.VideoCapture;
public class Main {
public static void main(String[] args) {
VideoCapture vc = new VideoCapture(0);
if(vc.isOpened()){
System.out.println("Works!");
}
}
}
i get
Exception in thread "main" java.lang.UnsatisfiedLinkError: org.opencv.highgui.VideoCapture.n_VideoCapture(I)J
at org.opencv.highgui.VideoCapture.n_VideoCapture(Native Method)
at org.opencv.highgui.VideoCapture.<init>(VideoCapture.java:113)
at Main.main(Main.java:5)
i add all the routes containes in:
C:\opencv\build\x64\vc10
one by one,but doesn`t work.
Finally i create a variable called OPENCV_DIR with C:\opencv\build\x64\vc10 but still getting UnsatisfiedLinkError.
PLEASE HELP ME!
in your second example , you skipped this line
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
so the opencv libs werent loaded, UnsatisfiedLinkError, etc...
[edit]:
thanks to @Jishnu Prathap for highlighting the java.library path issue, if you run into problems setting that, you can still try to use an absolute path to the java wrapper so/dll/dylib like:
System.load("/path to/our/java_wrapper");
I had a similar error while using OpenCV with java.I did 2 things to resolve it.
static{ System.loadLibrary(Core.NATIVE_LIBRARY_NAME); }
Try the below code
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import nu.pattern.OpenCV;
public class OpencvMain
{
public static void main( String[] args )
{
OpenCV.loadLocally();
Mat mat = Mat.eye( 3, 3, CvType.CV_8UC1 );
System.out.println( "mat = " + mat.dump() );
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With