Off Board Vision Processing in Java
This article describes how to get OpenCV, the WPILib Vision library, and NetworkTables, and how to build Java vision targeting programs that run on coprocessors that run alongside the roboRIO. This currently supports the following platforms:
- Raspberry Pi running Raspbian
- Generic Armhf devices (such as the BeagleBone Black or the Jetson)
It has been designed to be easy to setup and use, and only needs a few minor settings to pick which system you want to be ran on. It has samples for interfacing with NetworkTables and WPILib Vision Library (CsCore) from any device, along with performing OpenCV operations.
The system is setup to use Gradle to run the builds. Gradle is a cross platform build system, which only requires Java to run.
There are five steps to get your coprocessor configured for vision processing as shown below. This is just a template. You will need to add meaningful code to it for it to do what you want. After following the steps in this document you will have a zip file that you can copy on to your coprocessor, extract, and run.
- You can develop your vision program on a laptop or your coprocessor. Download the zip file located at https://github.com/wpilibsuite/VisionBuildSamples/releases to the device where you want to do your development.
- Extract the zip and open a command prompt to the extracted folder
Selecting which system to build for
As there is no way to autodetect which system you want to build for, such as building for a Raspberry Pi on a windows desktop, you have to manually select which system you want to build for.
- Open the
- To select your device uncomment the line it is on by removing the
- Save and exit
Selecting camera type
The sample includes 2 ways to get a camera image:
- Stream from roboRIO (HTTP Camera)
- USB Camera plugged into your coprocessor (not supported on Windows)
To select between the types, open the
Main.java file in
src/main/java, and scroll down to the line that says "Selecting a Camera". Remove the block comments around the type of camera you are going to use. If using the HTTP Camera, make sure to replace the "YourURLHere" with the URL to the stream of the camera. In the screenshots below, we have selected a USB Camera.
Building and Running
This sample program only serves video as an http mjpg stream to a web browser or your SmartDashboard and serves as a template. To add your own vision code, edit the java file and add your code there.
To build the project, run the command
./gradlew build . This will place the output files into the output directory. From there, you can run either the .bat file on windows or the shell script on unix in order to run your project on the local system. If you are programming on another computer, copy the zip file to the system you plan to run the vision code on, extract the zip file, and run the .bat or shell script to run the program.
An initial build with an internet connection is needed to download dependencies. After the initial build is complete, builds can be run without an internet connection by adding '--offline' to the build command:
./gradlew build --offline
You are not on the system you specified in the
build.gradle file. Please modify the build.gradle to match your system and run