user2717345
user2717345

Reputation:

library webcam-capture by sarxos not working on raspberry

i have a problem with the webcam-capture library for java on raspberry. This is my code:

    System.out.println("start");
    List<Webcam> list = Webcam.getWebcams();

    System.out.println("checking " + list.size() + " Webcams");
    for(Webcam webcam : list) {
        //do sth
    }

On windows i have the following output:

start
[main] INFO com.github.sarxos.webcam.Webcam - WebcamDefaultDriver capture    
driver will be used
checking 0 Webcams

On my raspberry i only get

start
[main] INFO com.github.sarxos.webcam.Webcam - WebcamDefaultDriver capture    
driver will be used

i tried to figure out the problematic code in the library and i found out that it exits at:

executor.awaitTermination(timeout, tunit);

in WebcamDiscoveryService.getWebcams()

the parameters are 9223372036854775807 and MILLISECONDS

why doesn't it work ("the project is portable (WinXP, Win7, Win8, Linux, Mac, Raspberry Pi) and does not require any additional software to be installed on the PC.").

is there maybe any other library that is that easy?

Upvotes: 1

Views: 2115

Answers (1)

Bartosz Firyn
Bartosz Firyn

Reputation: 2674

Just to record the solution I provided in the ticket created in Webcam Capture API project on Github in case anyone has the same issue and tries stackoverflow first.

The problem lies in the default driver which does not always run well on Raspberry Pi (only one BridJ version supports Raspberry Pi but it hasn't been released to Maven Central). To workaround this issue one can replace default driver which depends on BridJ by a different one, e.g. webcam-capture-driver-v4l4j which is most stable on Raspberry Pi, or by adding BridJ 0.6.3-SNAPSHOT to classpath instead of 0.6.2.

In case of webcam-capture-driver-v4l4j the JARs you have to include in your classpath are:

For Webcam Capture 0.3.10:

Or Webcam Capture 0.3.11:

After these are added, BridJ JAR can be removed from classpath as not required any more.

The code:

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

public static void main(String[] args) {
  JFrame frame = new JFrame("V4L4J Webcam Capture Driver Demo");
  frame.add(new WebcamPanel(Webcam.getDefault()));
  frame.pack();
  frame.setVisible(true);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

For more details I'm redirecting everyone interested to the ticket where issue has been resolved.

Upvotes: 1

Related Questions