Question

I'm currently beginning on a project where I want to capture and manipulate a datastream from my webcam in order to start I wanted to take some pictures from my webcam and show those to the user. However this gave an error.

public class quicktest  implements Runnable {
        public static void main(String[] args){
            Thread t=new Thread(new quicktest());
            t.start();
        }

        IplImage image;
        CanvasFrame canvas = new CanvasFrame("Web Cam");
        public quicktest() {
            canvas.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
        }
        @Override
        public void run() {
            FrameGrabber grabber = new VideoInputFrameGrabber(0); 

            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
                        // show image on window
                        canvas.showImage(img);
                    }
                     Thread.sleep(1000);
                }
            } catch (Exception e) {
            }
        }

this gives the following exception:

Exception in thread "Thread-3" java.lang.UnsatisfiedLinkError: no jnivideoInputLib in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1764)
    at java.lang.Runtime.loadLibrary0(Runtime.java:823)
    at java.lang.System.loadLibrary(System.java:1044)
    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.videoInputLib.<clinit>(videoInputLib.java:81)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:249)
    at com.googlecode.javacpp.Loader.load(Loader.java:561)
    at com.googlecode.javacpp.Loader.load(Loader.java:540)
    at com.googlecode.javacv.cpp.videoInputLib$videoInput.<clinit>(videoInputLib.java:193)
    at com.googlecode.javacv.VideoInputFrameGrabber.start(VideoInputFrameGrabber.java:101)
    at com.googlecode.javacv.VideoInputFrameGrabber.start(VideoInputFrameGrabber.java:98)
    at quicktest.run(quicktest.java:27)
    at java.lang.Thread.run(Thread.java:695)

I already searched and tried what was suggested here, however this gave me another error:

at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:249)
at com.googlecode.javacpp.Loader.load(Loader.java:561)
at com.googlecode.javacpp.Loader.load(Loader.java:540)
at com.googlecode.javacv.cpp.videoInputLib$videoInput.<clinit>(videoInputLib.java:193)
at Main.main(Main.java:5)

does anyone know how to fix this? By the way this happens on a macbook pro 10.7.5 and trying to use the build in webcam. And while it definably shouldn't matter there is also an ocules rift attached. Using the OpenCVFrameGrabber gave me a java.lang.UnsatisfiedLinkError: no jniopencv_highgui in java.library.path exception instead.

By the way if anyone knows another easy way to get images from my webcam into java that would be helpful to.

Having done what benny.la said I isntead get a

Exception in thread "Thread-3" java.lang.UnsatisfiedLinkError: no jnivideoInputLib in java.library.path

at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1764)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1044)
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.videoInputLib.<clinit>(videoInputLib.java:81)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:249)
at com.googlecode.javacpp.Loader.load(Loader.java:561)
at com.googlecode.javacpp.Loader.load(Loader.java:540)
at com.googlecode.javacv.cpp.videoInputLib$videoInput.<clinit>(videoInputLib.java:193)
at com.googlecode.javacv.VideoInputFrameGrabber.start(VideoInputFrameGrabber.java:101)
at com.googlecode.javacv.VideoInputFrameGrabber.start(VideoInputFrameGrabber.java:98)
at quicktest.run(quicktest.java:29)
at java.lang.Thread.run(Thread.java:695)

exception.

Was it helpful?

Solution

By the way if anyone knows another easy way to get images from my webcam into java that would be helpful to.

Since you're on a macbook, you could do something like:

Runtime.getRuntime().exec("screencapture tempfile.jpg");
InputStream in = new FileInputStream("tempfile.jpg");

OTHER TIPS

It seems like your JavaCV isn't set up correctly.

Have you done the following?

  1. Downloaded the xxx-bin.zip and the xxx-cppjars.zip from here
  2. Extract the .zip files
  3. Add the xxx-macosx-x86_64.jar to your eclipse project

The same problem I also faced. I use mac OSX with OpenCV-2.4.10 with Java CV 0.10

This problem I was getting when I was trying to run ColoredObjectTrack.java(present in javaCV-Samples) I used OpenCVFrameGrabber instead of VideoInputFrameGrabber. It worked.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top