-
Notifications
You must be signed in to change notification settings - Fork 1.1k
How To Configure Raspberry Pi
Connect your camera module and configure in accordance to the instruction provided in the Raspberry Pi Documentation (enable it in raspi-config
).
If it's visible as /dev/videoN
(N
is some number, usually 0
if you do not have UVC devices connected to USB), you are free to go ahead. If this file is not available, then execute:
$ sudo modprobe bcm2835-v4l2
Please note that above will create video file only once. To make it permanent you need to run it at the boot time (e.g. by including this in /etc/rc.local
).
More details on kernel camera module can be found here.
After the modprobe
is done (may require RasPi restart) you will need to replace default capture driver with the webcam-capture-driver-v4l4j which is best suited to work with RasPi.
The following JARs are required:
- The webcam-capture-driver-v4l4j JAR can be found here, and
- The V4L4J JAR itself which can be found here (the project and source code is available here).
Example Java code:
static {
Webcam.setDriver(new V4l4jDriver()); // this is important
}
public static void main(String[] args) {
JFrame frame = new JFrame("Hello From RasPi Camera Module");
frame.add(new WebcamPanel(Webcam.getDefault()));
frame.pack();
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
Now you can freely to use Webcam Capture API on your RasPi.
(Not the RasPi Camera Module)
It's enough to replace default capture driver with the webcam-capture-driver-v4l4j which is best suited to work with RasPi. No additional configuration is required. Please note that some camera devices has energy consumption higher than your RasPi can handle. In this case camera device may not work properly or even refuse to boot.
From the Java code perspective, there is no difference if the camera is UVC or RasPi Camera Module:
static {
Webcam.setDriver(new V4l4jDriver()); // this is important
}
public static void main(String[] args) {
JFrame frame = new JFrame("Hello From UVC Camera");
frame.add(new WebcamPanel(Webcam.getDefault()));
frame.pack();
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
Depending on what capture driver you want to use, you need to have appropriate software installed on your Pi.
$ sudo apt-get update
$ sudo apt-get install vlc
$ sudo apt-get install oracle-java7-jdk
Use the following artifacts:
- com.github.sarxos:webcam-capture:jar:0.3.10
- org.slf4j:slf4j-api:jar:1.7.2
- com.github.sarxos:webcam-capture-driver-vlcj:jar:0.3.10
- uk.co.caprica:vlcj:jar:2.4.1
- net.java.dev.jna:jna:jar:4.1.0