Skip to content

Latest commit

 

History

History

java

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

Java samples and code

To get this sample to run, you must install OpenCV on your local machine. You will need Apache Ant to build the executable JAR file app.

Your environment should define the following environment variables:

  • JAVA_HOME = the directory containing your JDK
  • ANT_HOME = the directory in which Apache Ant is installed
  • OPENCV_HOME = the directory in which all of OpenCV is installed
  • OPENCV_LIB = the directory containing all native JNI libraries
  • OPENCV_JAR = the path to the JAR file containing the java interface to OpenCV (typically named something like "opencv-320.jar" )

Execute the code by changing to the directory for GRIP-code-generation/java and then executing "ant run". Or, can can run the application by executing:

java -Djava.library.path=${OPENCV_LIB} -jar build/grip_sample1.jar

Installing OpenCV using the WPIRoboticsProjects opencv-installer

To get OpenCV on your machine, you should use the prebuild intaller from WPIRoboticsProjects.

This tool allows you to define where the "java" and "jni" code will be stored.

  • OPENCV_JAR should point to the JAR file copied into your "java" directory
  • OPENCV_LIB should point to the directory in which your "jni" artifacts have been copied.

If this tool doesn't work for your deployment setup (or if you want to use a version of OpenCV not hosted by FIRST), you may install OpenCV as detailed below:

Installing OpenCV on Windows

Windows is the easiest install, because the OpenCV site has everything precompiled.

Download and unzip OpenCV for Windows.

  • OPENCV_JAR will be at ${OPENCV_HOME}/build/java/opencv-320.jar
  • OPENCV_LIB will be at ${OPENCV_HOME}/build/java/x86

Installing OpenCV on Linux, including Raspberry Pi

For Linux operating systems, you'll need to build everything.

The build process takes a long time, especially on a Raspberry Pi. Follow the instructions carefully and you'll be OK. You can start by cloning the github repository or you can start by downloading the OpenCV for Linux/Mac ZIP file.

  • OPENCV_JAR will be at ${OPENCV_HOME}/build/bin/opencv-320.jar
  • OPENCV_LIB will be at ${OPENCV_HOME}/build/lib

The GRIP wiki contains additional instructions on running pipelines on the Raspberry pi.

Installing OpenCV on MacOS

A Macintosh install is similar to building on Linux, except you may need to take extra steps to get the build tools. You will need the Mac version of cmake and you'll need to install Apache Ant.

Just like in Linux, the environment variables defined in your .bash_profile should be:

  • OPENCV_JAR will be at ${OPENCV_HOME}/build/bin/opencv-320.jar
  • OPENCV_LIB will be at ${OPENCV_HOME}/build/lib

Using OpenCV in Eclipse

In Eclipse you should define a "User Library" for OpenCV. Open the Eclipse preferences dialog and go to Java / Build Path / User Libraries. Create a new User Library named "opencv-3.2.0". To this library, attach 'opencv-320.jar' as an external JAR. Then, expand that JAR reference and specify the Native Library Location to be your OPENCV_LIB directory.

To use OpenCV in a Eclipse Java project, open the project's properties dialog and add the new user library to the Java Build Path Libraries.