Building Java OpenCV on the BeagleBone Black or Raspberry Pi

Step 1: Install Ubuntu or a similar distribution on your board
This tutorial assumes that you already have Ubuntu or something similar installed on you board. If not, there are may tutorials available online on how to do so.

Step 2: Install a JDK

Update if you haven’t done so already

We will need a JDK so we build OpenCV and build Java applications for it.

This will give us a list of available JDKs for our baord

This will install openjdk-6

Step 3: Install dependencies

Update if you haven’t done so already

Later in the build step, in order to build the OpenCV .jar file, we will need ant.

This should install ant

Additionally we will need other packages to build OpenCV. Try to install as much as you can from the list. If they are not available try to look for newer version of them.

Step 4: Build OpenCV from the git repository

Install git if not already installed

Clone OpenCV from the rpository

Build OpenCV

Make sure Java is in the list of modules to be built. If not look at CMake output to figure out why. Usually this is caused because you are missing some java related tools such as ant or a JDK.

The make process will take 4-6 hrs so go to sleep, work, or whatever… Comeback after it is done.

The build process will generate .jar and a .so file which is what we need for java development.

If CMake is unable to find Java, make sure that the JAVA_HOME environment variable points to the path of your JDK

Step 5: Setup

Place the generated inside your jdk folder under the arm folder.

Step 6: Test Application Development in Eclipse on Development PC

Download OpenCV for your PC if you haven’t done so already

Configure Eclipse:

Follow the steps found at

Note: For Windows we need the .dll file and .so file linux

Hello OpenCV

If this works you are done and should ready to explore all that OpenCV has to offer.

Simple OpenCV Webcam Application

Obviously you will need a webcam for this to work.

Step 7: Transferring a java application/project to the BBB or other target board

The easiest way to transfer a java application/project into the BBB is to simply transferring the files and compiling it there.

Extract the opencv-2xx.jar and transfer the files to your project folder in the BBB.
Note: You can also just include the jar file in your classpath when compiling your application but I was never able to get this to properly to work.

You can download my sample project on the BBB here

If you get errors, make sure that the .so file is in the arm folder in your jdk directory as stated in step 5.

Angstrom workaround

I had some trouble successfully building OpenCV under the Angstrom distribution. Mainly because I was not able to find an easy way to install some of the dependencies and Ant. I worked around this by loading Ubuntu on a separate SD card then building OpenCV there. I then grabbed the generated .jar and .so file which I used for my Java development.

A good amount of content for this tutorial was taken/borrowed/stolen from:

You might also want to checkout these useful sites:


Leave a Reply

Your email address will not be published. Required fields are marked *