sarxos / webcam-capture

The goal of this project is to allow integrated or USB-connected webcams to be accessed directly from Java. Using provided libraries users are able to read camera images and detect motion. Main project consist of several sub projects - the root one, which contains required classes, build-in webcam driver compatible with Windows, Linux and Mac OS, which can stream images as fast as your camera can serve them (up to 50 FPS). Main project can be used standalone, but user is able to replace build-in driver with different one - such as OpenIMAJ, GStreamer, V4L4j, JMF, LTI-CIVIL, FMJ, etc.
http://webcam-capture.sarxos.pl
MIT License
2.26k stars 1.11k forks source link

Problem in connecting to webcam using JavaCv Driver #238

Open rakeshbhatt10 opened 10 years ago

rakeshbhatt10 commented 10 years ago

HI Sarxos,

I am currently trying to use your JavaCv driver i downloaded your JavaCv Driver project and and setup lib folder including JavaCv 0.8 jars, webcam-capture-0.3.10-RC7.jar add them into classpath. But while i run it it is giving me exception

stacktrace is below:

Exception in thread "main" com.github.sarxos.webcam.WebcamException: java.util.concurrent.ExecutionException: java.lang.UnsatisfiedLinkError: no jnivideoInputLib in java.library.path
    at com.github.sarxos.webcam.WebcamDiscoveryService.getWebcams(WebcamDiscoveryService.java:124)
    at com.github.sarxos.webcam.Webcam.getWebcams(Webcam.java:796)
    at com.github.sarxos.webcam.Webcam.getWebcams(Webcam.java:769)
    at com.github.sarxos.webcam.Webcam.getWebcams(Webcam.java:749)
    at com.test.JavaCvDriverExample.main(JavaCvDriverExample.java:17)
Caused by: java.util.concurrent.ExecutionException: java.lang.UnsatisfiedLinkError: no jnivideoInputLib in java.library.path
    at java.util.concurrent.FutureTask$Sync.innerGet(Unknown Source)
    at java.util.concurrent.FutureTask.get(Unknown Source)
    at com.github.sarxos.webcam.WebcamDiscoveryService.getWebcams(WebcamDiscoveryService.java:116)
    ... 4 more
Caused by: java.lang.UnsatisfiedLinkError: no jnivideoInputLib in java.library.path
    at java.lang.ClassLoader.loadLibrary(Unknown Source)
    at java.lang.Runtime.loadLibrary0(Unknown Source)
    at java.lang.System.loadLibrary(Unknown Source)
    at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:524)
    at org.bytedeco.javacpp.Loader.load(Loader.java:399)
    at org.bytedeco.javacpp.Loader.load(Loader.java:353)
    at org.bytedeco.javacpp.videoInputLib.<clinit>(videoInputLib.java:10)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at org.bytedeco.javacpp.Loader.load(Loader.java:374)
    at org.bytedeco.javacpp.Loader.load(Loader.java:353)
    at org.bytedeco.javacpp.videoInputLib$videoInput.<clinit>(videoInputLib.java:330)
    at com.github.sarxos.webcam.ds.javacv.JavaCvDriver.getDevicesWindows(JavaCvDriver.java:29)
    at com.github.sarxos.webcam.ds.javacv.JavaCvDriver.getDevices(JavaCvDriver.java:54)
    at com.github.sarxos.webcam.WebcamDiscoveryService$WebcamsDiscovery.call(WebcamDiscoveryService.java:36)
    at com.github.sarxos.webcam.WebcamDiscoveryService$WebcamsDiscovery.call(WebcamDiscoveryService.java:26)
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.UnsatisfiedLinkError: no uuid in java.library.path
    at java.lang.ClassLoader.loadLibrary(Unknown Source)
    at java.lang.Runtime.loadLibrary0(Unknown Source)
    at java.lang.System.loadLibrary(Unknown Source)
    at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:524)
    at org.bytedeco.javacpp.Loader.load(Loader.java:390)

While the error is related to

java.util.concurrent.ExecutionException: java.lang.UnsatisfiedLinkError:

But when i run JavaCV samples it runs fine. So if this is the linking problem JavaCv examples would not run either

I am currently using OpenCV 2.4.9 and JavaCv 0.8.

I also want to ask one more thing

You had written title of frame in example of JavaCv Driver as ":LTI-CIVIL Webcam Capture Driver Example" which is also i didn't understood if we use JavaCV it will use OpencvFFMPEGDriver or FFMPEGDriver for camera connectivity. But lit-civil will require different set of c++ header files please clarify me i am a newbie into this:

Thanks is advance Rakesh Bhatt

sarxos commented 10 years ago

Hi @rakeshbhatt10,

Have you added opencv bin to PATH? Is this Windows or Linux? Can you post both examples you are referring to and the way of how you run them?

Yes, the frame title is incorrect. I duplicated this example from LTI-CIVIL driver and forget to change title.

rakeshbhatt10 commented 10 years ago

Hi Sarxos,

I have added opencv bin to path which is: C:\opencv\build\x86\vc10\bin . I am currently using Windows 7.

Example to connect to webcam with JavaCV is below:

public class Demo {

    public static void main(String[] args) throws Exception {

        Loader.load(opencv_objdetect.class);
        FrameGrabber grabber = FrameGrabber.createDefault(1);
        grabber.start();
        IplImage grabbedImage = grabber.grab();
        CvMemStorage storage = CvMemStorage.create();
        CanvasFrame frame = new CanvasFrame("Some Title", CanvasFrame.getDefaultGamma()/grabber.getGamma());
        frame.setVisible(true);
        while (frame.isVisible() && (grabbedImage = grabber.grab()) != null) {
            cvClearMemStorage(storage);
            frame.showImage(grabbedImage);
        }
        frame.dispose();
        grabber.stop();
    }
}

This example is working fine and provide me camera preview

Example with your JavaCV driver to connect with webcam is below

public class JavaCvDriverExample {

    static {
        Webcam.setDriver(new JavaCvDriver());
    }

    public static void main(String[] args) {
        JFrame frame = new JFrame("LTI-CIVIL Webcam Capture Driver Example");
        frame.add(new WebcamPanel(Webcam.getWebcams().get(1)));
        frame.pack();
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}

This code gives me unsatisfied link error : If the configuration is not right my JavaCv example should also not work. but JavaCv example is working fine

Thanks,

qweasdzxcpoi commented 7 years ago

@sarxos How to add opencv bin to PATH

ex: my path to bin is /home/chandansr/opencv-2.4.9/build/bin