Difference between revisions of "Raspberry PI"
m |
m |
||
Line 1: | Line 1: | ||
# Replacing Default Java | Raspberry PI's (RPI) are low cost and very popular ARM devices hobby projects. BoofCV is very easy to set up and run on RPI's. Just compare my experience getting OpenCV and BoofCV up and running ([http://peterabeles.com/blog/?p=241 article]). Basically hours in a best case scenario vs minutes for BoofCV. Things change constantly so maybe it has gotten better since then. It also runs quite fast and well. Check out this these [[Performance:OpenCV:BoofCV|benchmark]] results. | ||
As is often the case with a RPI to get everything working well and working with your hardware (i.e. a camera) there will be some assembly required. Just as an example, let's say you want to use a RPI to scan QR codes using the RPI camera you need to do the following: | |||
# Replace the JDK | |||
# Setup the RPI Camera | |||
# Build and Run The Example Project | |||
Got an RPI running as a desktop machine? You should run the BoofCV demonstration applications! They mostly work. Cameras can be a bit of an issue though. RPI camera requires injecting special code that the demo application's don't have. USB cameras also work but USB is slow on a RPI. Here are the steps you need to follow | |||
# Replace the JDK | |||
# Download and Run Demonstrations | |||
__FORCETOC__ | |||
= Replacing Default Java = | |||
The default Java installation on Raspberry PI is not optimized for running on ARM and runs much, much slower than it should. You will need to download another version and use that. | The default Java installation on Raspberry PI is not optimized for running on ARM and runs much, much slower than it should. You will need to download another version and use that. | ||
Line 8: | Line 24: | ||
# Add it to your path | # Add it to your path | ||
= Building BoofCV = | |||
You can build BoofCV the usual way, just make sure you use Java 11 or newer to do so and install the ARM optimized JDK! On a regular desktop it takes about 1 minute to build, but on a Raspberry PI it can take 10 minutes or so. | You can build BoofCV the usual way, just make sure you use Java 11 or newer to do so and install the ARM optimized JDK! On a regular desktop it takes about 1 minute to build, but on a Raspberry PI it can take 10 minutes or so. | ||
Line 14: | Line 30: | ||
To build and install into your local Maven repository: | To build and install into your local Maven repository: | ||
<syntaxhighlight lang="bash"> | |||
cd boofcv | cd boofcv | ||
./gradlew install | ./gradlew install | ||
</syntaxhighlight> | |||
If you are running your Raspberry PI as a Desktop you can run the demonstration apps. Might also want to plug a camera in or setup your Raspberry PI camera as discussed below. | If you are running your Raspberry PI as a Desktop you can run the demonstration apps. Might also want to plug a camera in or setup your Raspberry PI camera as discussed below. | ||
< | <syntaxhighlight lang="bash"> | ||
cd boofcv | cd boofcv | ||
./gradlew demonstrations | ./gradlew demonstrations | ||
java -jar demonstrations/demonstrations.jar | java -jar demonstrations/demonstrations.jar | ||
</ | </syntaxhighlight> | ||
Trouble Shooting: | Trouble Shooting: | ||
If the `./gradlew` command fails and complains about Java 11 that means you didn't download Java 11 yet or your path is incorrect. One way to get around that is to force Gradle to use a specific JDK. | If the `./gradlew` command fails and complains about Java 11 that means you didn't download Java 11 yet or your path is incorrect. One way to get around that is to force Gradle to use a specific JDK. | ||
< | |||
<syntaxhighlight lang="bash"> | |||
/gradlew -Dorg.gradle.java.home=/path/to/jdk-11/ demonstrations | /gradlew -Dorg.gradle.java.home=/path/to/jdk-11/ demonstrations | ||
</ | </syntaxhighlight> | ||
= Why don't webcams work = | |||
BoofCV uses Webcam Capture and in it's default configuration it doesn't work on Raspberry PI. The good news is that there is a simple fix that needs to be added to your source code to get it to run on Raspberry PI! https://github.com/sarxos/webcam-capture/wiki/How-To-Configure-Raspberry-Pi | BoofCV uses Webcam Capture and in it's default configuration it doesn't work on Raspberry PI. The good news is that there is a simple fix that needs to be added to your source code to get it to run on Raspberry PI! https://github.com/sarxos/webcam-capture/wiki/How-To-Configure-Raspberry-Pi | ||
Line 39: | Line 58: | ||
= How do I use the Raspberry PI Camera? = | |||
The easiest way to access the camera is to treat it as a UVC device. This way WebcamCapture will recognize it and all the example code will work. Unfortunately, you have to tell your Raspberry PI to load the UVC driver each time you boot by doing the following ([https://raspberrypi.stackexchange.com/questions/10480/raspi-camera-board-and-motion Stack Exchange]): | The easiest way to access the camera is to treat it as a UVC device. This way WebcamCapture will recognize it and all the example code will work. Unfortunately, you have to tell your Raspberry PI to load the UVC driver each time you boot by doing the following ([https://raspberrypi.stackexchange.com/questions/10480/raspi-camera-board-and-motion Stack Exchange]): | ||
< | <syntaxhighlight lang="bash"> | ||
sudo modprobe bcm2835-v4l2 | sudo modprobe bcm2835-v4l2 | ||
</ | </syntaxhighlight> | ||
It should now show up in the list of cameras if you type v4l2-ctl --list-devices. This is what I see on my system. I also have a webcam plugged in to USB that's why there are two devices: | It should now show up in the list of cameras if you type v4l2-ctl --list-devices. This is what I see on my system. I also have a webcam plugged in to USB that's why there are two devices: | ||
< | <pre> | ||
mmal service 16.1 (platform:bcm2835-v4l2): | mmal service 16.1 (platform:bcm2835-v4l2): | ||
/dev/video1 | /dev/video1 | ||
Line 55: | Line 74: | ||
Logitech Webcam C930e (usb-3f980000.usb-1.1.3.1): | Logitech Webcam C930e (usb-3f980000.usb-1.1.3.1): | ||
/dev/video0 | /dev/video0 | ||
</ | </pre> | ||
/dev/video1 is the device associated with the Raspberry PI camera. | /dev/video1 is the device associated with the Raspberry PI camera. |
Revision as of 15:02, 26 April 2020
Raspberry PI's (RPI) are low cost and very popular ARM devices hobby projects. BoofCV is very easy to set up and run on RPI's. Just compare my experience getting OpenCV and BoofCV up and running (article). Basically hours in a best case scenario vs minutes for BoofCV. Things change constantly so maybe it has gotten better since then. It also runs quite fast and well. Check out this these benchmark results.
As is often the case with a RPI to get everything working well and working with your hardware (i.e. a camera) there will be some assembly required. Just as an example, let's say you want to use a RPI to scan QR codes using the RPI camera you need to do the following:
- Replace the JDK
- Setup the RPI Camera
- Build and Run The Example Project
Got an RPI running as a desktop machine? You should run the BoofCV demonstration applications! They mostly work. Cameras can be a bit of an issue though. RPI camera requires injecting special code that the demo application's don't have. USB cameras also work but USB is slow on a RPI. Here are the steps you need to follow
- Replace the JDK
- Download and Run Demonstrations
Replacing Default Java
The default Java installation on Raspberry PI is not optimized for running on ARM and runs much, much slower than it should. You will need to download another version and use that.
- Download JDK built for Raspberry PI
- Decompress `tar -xzf jdk.tar.gz`
- Move to a location you like `sudo mv jdk-11 /opt`
- Add it to your path
Building BoofCV
You can build BoofCV the usual way, just make sure you use Java 11 or newer to do so and install the ARM optimized JDK! On a regular desktop it takes about 1 minute to build, but on a Raspberry PI it can take 10 minutes or so.
To build and install into your local Maven repository:
cd boofcv
./gradlew install
If you are running your Raspberry PI as a Desktop you can run the demonstration apps. Might also want to plug a camera in or setup your Raspberry PI camera as discussed below.
cd boofcv
./gradlew demonstrations
java -jar demonstrations/demonstrations.jar
Trouble Shooting:
If the `./gradlew` command fails and complains about Java 11 that means you didn't download Java 11 yet or your path is incorrect. One way to get around that is to force Gradle to use a specific JDK.
/gradlew -Dorg.gradle.java.home=/path/to/jdk-11/ demonstrations
Why don't webcams work
BoofCV uses Webcam Capture and in it's default configuration it doesn't work on Raspberry PI. The good news is that there is a simple fix that needs to be added to your source code to get it to run on Raspberry PI! https://github.com/sarxos/webcam-capture/wiki/How-To-Configure-Raspberry-Pi
It should also be pointed out that you don't have to use any of built in tools. You just need a way to convert the image into format that BoofCV understands. Once you got the bytes for an image that is often "simple" if you understad image formats.
How do I use the Raspberry PI Camera?
The easiest way to access the camera is to treat it as a UVC device. This way WebcamCapture will recognize it and all the example code will work. Unfortunately, you have to tell your Raspberry PI to load the UVC driver each time you boot by doing the following (Stack Exchange):
sudo modprobe bcm2835-v4l2
It should now show up in the list of cameras if you type v4l2-ctl --list-devices. This is what I see on my system. I also have a webcam plugged in to USB that's why there are two devices:
mmal service 16.1 (platform:bcm2835-v4l2): /dev/video1 Logitech Webcam C930e (usb-3f980000.usb-1.1.3.1): /dev/video0
/dev/video1 is the device associated with the Raspberry PI camera.