Ask Your Question
0

Java Webcam Capture

asked 2013-10-01 07:49:27 -0600

lobi gravatar image

updated 2013-10-01 08:43:45 -0600

Hello,

I'm trying to learn openCV (java). I have started with simple project (capture video with webcam). Here is a code (I'm using eclipse).

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.highgui.VideoCapture;

public class Main {
    public static void main(String[] args) {

        //System.loadLibrary("opencv-246.jar");
        VideoCapture cap = new VideoCapture(0);
        Mat frame = new Mat();
        cap.retrieve(frame);

    }
}

When I run my code I'm get this error:

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:10)

Can please someone help me.

Thank you very much.

Best

I reset my lib. But still get the same error. image description

Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv-246.jar in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1874) at java.lang.Runtime.loadLibrary0(Runtime.java:849) at java.lang.System.loadLibrary(System.java:1087) at Main.main(Main.java:9)

edit retag flag offensive close merge delete

Comments

//System.loadLibrary("opencv-246.jar");

why did you comment it ? you need it !

also, make sure that the opencv dlls are on the PATH env var

berak gravatar imageberak ( 2013-10-01 07:52:18 -0600 )edit

If I uncomment this out. I get this error Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv-246.jar in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1874) at java.lang.Runtime.loadLibrary0(Runtime.java:849) at java.lang.System.loadLibrary(System.java:1087) at Main.main(Main.java:8)

lobi gravatar imagelobi ( 2013-10-01 07:55:59 -0600 )edit

berak, can you please show hot to set this "also, make sure that the opencv dlls are on the PATH env var" thanks

lobi gravatar imagelobi ( 2013-10-01 15:34:55 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
0

answered 2013-12-09 11:17:31 -0600

i got d same result goto preferences n just giv both the native paths to opencv/java/build/x64

edit flag offensive delete link more
0

answered 2013-12-10 10:36:06 -0600

You must load the appropriate OpenCV dll's with accordance to the system architecture you are using. Mine is placed in the 'lib\opencv' directory inside my project folder.

    String currentDir = new File("").getAbsolutePath();
    String arch = System.getProperty("sun.arch.data.model");

    switch (arch) {
        case "64":
            System.load(currentDir + "\\lib\\opencv\\x64\\opencv_java247.dll");
            break;
        case "32":
            System.load(currentDir + "\\lib\\opencv\\x86\\opencv_java247.dll");
            break;
    }
edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2013-10-01 07:49:27 -0600

Seen: 5,596 times

Last updated: Dec 10 '13