简体   繁体   中英

Webcam Capture API -How to get it work on Raspberry Pi?

This is my first post in stackoverflows forum.

I like to refer this sarxos answer https://stackoverflow.com/a/31871593/5510077

I think I have followed API's creator Bartosz Firyns instructions exactly to get his Webcam Capture 0.3.10 API to work on my Raspberry Pi Model B+.

Files I have currently included in my classpath are:

  • slf4j-api-1.7.2.jar
  • slf4j-simple-1.7.2.jar
  • v4l4j-0.9.1-r507.jar
  • webcam-capture-0.3.10.jar
  • webcam-capture-driver-v4l4j-0.3.10-20140923.154112-11.jar

I use this sarxos's example to test API, but using V4l4jDriver, because I can't get BridJ work on Raspberry Pi :

package webcam;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import com.github.sarxos.webcam.Webcam;
import com.github.sarxos.webcam.ds.v4l4j.V4l4jDriver;

public class WebCam {

    static {
        Webcam.setDriver(new V4l4jDriver()); // this is important
    }

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

        // get default webcam and open it
        Webcam webcam = Webcam.getDefault();
        webcam.open();

        // get image
        BufferedImage image = webcam.getImage();

        // save image to PNG file
        ImageIO.write(image, "PNG", new File("test.png"));
    }
}

and receive this error:

[main] WARN com.github.sarxos.webcam.ds.v4l4j.V4l4jDriver - Modified V4L4J has not been found in classpath
Exception in thread "main" com.github.sarxos.webcam.WebcamException: java.util.concurrent.ExecutionException: java.lang.NullPointerException
    at com.github.sarxos.webcam.WebcamDiscoveryService.getWebcams(WebcamDiscoveryService.java:124)
    at com.github.sarxos.webcam.Webcam.getWebcams(Webcam.java:816)
    at com.github.sarxos.webcam.Webcam.getDefault(Webcam.java:879)
    at com.github.sarxos.webcam.Webcam.getDefault(Webcam.java:856)
    at com.github.sarxos.webcam.Webcam.getDefault(Webcam.java:834)
    at webcam.WebCam.main(WebCam.java:34)
Caused by: java.util.concurrent.ExecutionException: java.lang.NullPointerException
    at java.util.concurrent.FutureTask.report(FutureTask.java:122)
    at java.util.concurrent.FutureTask.get(FutureTask.java:192)
    at com.github.sarxos.webcam.WebcamDiscoveryService.getWebcams(WebcamDiscoveryService.java:116)
    ... 5 more
Caused by: java.lang.NullPointerException
    at com.github.sarxos.webcam.util.NixVideoDevUtils.getVideoFiles(NixVideoDevUtils.java:19)
    at com.github.sarxos.webcam.ds.v4l4j.V4l4jDriver.getDevices(V4l4jDriver.java:46)
    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.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Java Result: 1

These links are dead so I can't test these jar-files:

webcam-capture-0.3.11-SNAPSHOT.jar

webcam-capture-driver-v4l4j-0.3.11-20150713.101304-10.jar

Is there anything to do to get this API working on Raspberry Pi on these days?

You get rid of the error and application running when you replace two files:

    webcam-capture-0.3.10.jar

with this one:

    webcam-capture-0.3.11.jar

and

    webcam-capture-driver-v4l4j-0.3.10-20140923.154112-11.jar

with this one

    webcam-capture-driver-v4l4j-0.3.11.jar

Links to these files and answered ticket from Webcam Capture API author to missing links.

the program above is causing lots of error on latest rpi. please use the following example https://blogs.msdn.microsoft.com/robert_mcmurray/2015/06/12/simple-java-wrapper-class-for-raspistill-on-the-raspberry-pi-2/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM