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

Issues running on Raspberry Pi 5 #939

Closed SWSpratlin closed 1 week ago

SWSpratlin commented 2 weeks ago

Using the V4L4J Driver, I consistently run into a "NoSuchFieldException: usr_paths"

I think it has something to do with loading the "loadLibraryFromJar" method, but I'm not experienced enough to really troubleshoot that. Seems like the "usr_paths" isn't getting created properly, potentially because of permissions, but I'm not totally sure.

Using an ArduCam module, conencted with the ribbon cable. I can get picture from it with libcamera-hello but not with v4l2-ctl

SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details.
java.io.IOException: java.lang.NoSuchFieldException: usr_paths
    at com.github.sarxos.v4l4j.NativeUtils.loadLibraryFromJar(NativeUtils.java:62)
    at com.github.sarxos.v4l4j.V4L4J.init(V4L4J.java:50)
    at com.github.sarxos.webcam.ds.v4l4j.V4l4jDriver.<clinit>(V4l4jDriver.java:33)
    at sarxtest.CamHandler.initDriver(CamHandler.java:34)
    at sarxtest.CamHandler.<init>(CamHandler.java:20)
    at sarxtest.HandlerTests.settings(HandlerTests.java:25)
    at processing.core.PApplet.handleSettings(PApplet.java:853)
    at processing.core.PApplet.runSketch(PApplet.java:10113)
    at sarxtest.HandlerTests.main(HandlerTests.java:87)
Caused by: java.lang.NoSuchFieldException: usr_paths
    at java.base/java.lang.Class.getDeclaredField(Class.java:2792)
    at com.github.sarxos.v4l4j.NativeUtils.addLibraryPath(NativeUtils.java:109)
    at com.github.sarxos.v4l4j.NativeUtils.loadLibraryFromJar(NativeUtils.java:60)
    ... 8 more
com.github.sarxos.webcam.WebcamException: java.util.concurrent.ExecutionException: java.lang.UnsatisfiedLinkError: 'long au.edu.jcu.v4l4j.VideoDevice.doInit(java.lang.String)'
    at com.github.sarxos.webcam.WebcamDiscoveryService.getWebcams(WebcamDiscoveryService.java:124)
    at com.github.sarxos.webcam.Webcam.getWebcams(Webcam.java:893)
    at com.github.sarxos.webcam.Webcam.getWebcams(Webcam.java:866)
    at com.github.sarxos.webcam.Webcam.getWebcams(Webcam.java:845)
    at sarxtest.CamHandler.initCam(CamHandler.java:55)
    at sarxtest.HandlerTests.settings(HandlerTests.java:26)
    at processing.core.PApplet.handleSettings(PApplet.java:853)
    at processing.core.PApplet.runSketch(PApplet.java:10113)
    at sarxtest.HandlerTests.main(HandlerTests.java:87)
Caused by: java.util.concurrent.ExecutionException: java.lang.UnsatisfiedLinkError: 'long au.edu.jcu.v4l4j.VideoDevice.doInit(java.lang.String)'
    at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122)
    at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191)
    at com.github.sarxos.webcam.WebcamDiscoveryService.getWebcams(WebcamDiscoveryService.java:116)
    ... 8 more
Caused by: java.lang.UnsatisfiedLinkError: 'long au.edu.jcu.v4l4j.VideoDevice.doInit(java.lang.String)'
    at au.edu.jcu.v4l4j.VideoDevice.doInit(Native Method)
    at au.edu.jcu.v4l4j.VideoDevice.<init>(VideoDevice.java:271)
    at com.github.sarxos.webcam.ds.v4l4j.V4l4jDevice.getVideoDevice(V4l4jDevice.java:105)
    at com.github.sarxos.webcam.ds.v4l4j.V4l4jDevice.<init>(V4l4jDevice.java:89)
    at com.github.sarxos.webcam.ds.v4l4j.V4l4jDriver.getDevices(V4l4jDriver.java:49)
    at com.github.sarxos.webcam.WebcamDiscoveryService$WebcamsDiscovery.call(WebcamDiscoveryService.java:36)
    at com.github.sarxos.webcam.WebcamDiscoveryService$WebcamsDiscovery.call(WebcamDiscoveryService.java:26)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
    at java.base/java.lang.Thread.run(Thread.java:1570)

Any help would be appreciated.

alexmao86 commented 1 week ago

this lib is fully tested JDK8 and x86 Linux, windows and armv7. so for later aar64 and etc, this lib is not tested. on other side, the vl4j bridj .... native code are out of date because of JDK new features. so use OPENCV driver which uses javacv is strongly recommended.

thanks

SWSpratlin commented 1 week ago

I just saw on the documentation that V4L4J was the preferred driver for Raspberry Pi, so I wanted to go through that channel. I can give a shot to OpenCV, but will that cause issues with the Pi hardware?

SWSpratlin commented 1 week ago

Returning to this issue, as its running into trouble with the 4+ versions of openCV/

SWSpratlin commented 1 week ago

I think there's an issue with how the videoio.VideoCapture class is being called in the JavaCvDriver class, this is only present in the snapshot versions on maven, will try to build on my own from source

SWSpratlin commented 1 week ago

Closing this issue as resolved. Will open another potentially.

Issue comes from the JavaCVDriver class. Needs updating in the import statements to reflect changes in javacpp, javacv, and opencv from bytedeco.

I don't know how to submit a push/pull request so I'll detail my solution.

VideoCapture and VideoInput classes need an update to their import statments in the JavaCVDriver class

import org.bytedeco.opencv.opencv_videoio.VideoCapture;
import org.bytedeco.videoinput.videoInput;

works for me.

SWSpratlin commented 1 day ago

I was in fact wrong, that did not work for me.

The real solution for me was quite different. Context: Running Debian Bookworm on a Raspberry Pi 5. Java 17, Maven installed, Pi Cam Module 3.

The solution that worked for me was the following:

This SHOULD work, but will likely need troubleshooting on other Pi systems with different packages installed than I currently have. This setup is currently stable for 12+ hour runs.

This was a long, involved process. Since Pi switched away from the framework that they used to use for their cameras (/dev/video0, etc.), you need to adjust your driver files manually to fix these problems.