Wednesday, December 23, 2015

OpenCV 3.1 with Java Support on OsX El Capitan V10.11.1

In this blog post I'll describe what you have to do in order to build OpenCV 3.1 with Java Support on a Mac with El Capitan.

Painting the tanker 'Borgsten'

(If you don't want to do source builds and you don't have all necessary tools installed, there are also some alternatives like brew or macports available. In fact, I blogged about using this approach some years ago.)

Compiling OpenCV 3.1

First, you will have to download the sources directly from the official site. It is a rather large source distribution, so the download may take a while.

Unpack the source ball into a directory, I did it like this:

~/opencv/ (1)
~/opencv/opencv-3.1.0/ (2)

I created a directory named "build"

~/opencv/build/ (3)

(1) ... a directory which includes all opencv versions, so you have everything in place if you want to follow more than one version and you don't use git for doing this
(2) ... the sources like you've downloaded them
(3) ... the build directory which will be cluttered up by cmake with all kinds of stuff

Change to the directory (3) and issue following command:

cmake ../opencv-3.1.0/

This command will investigate what is already installed on your system. It will do its best to download stuff it will need to compile what is possible. Certain tools or libraries you still need to download manually, though. This command will finish in a minute and end with a thorough report of how the build is configured. Check this list and see if your feature is configured aswell. To my surprise and as opposed to the last try with version 2.4.6 the java bindings are activated per default which is great. Huge thanks for the build guys of this library.

The cmake command is setup in a way that in theory you just have to invoke another command, named


which will invoke by itself all programs which contribute to the final build artifacts. This means it will invoke c++ compilers, c compilers, helper programs and whatnot. This command will also take some time to complete.

After waiting for some minutes the command exits successfully and in the bin folder there is a jar file which contains all bindings to the opencv library. This API is then the entrance for using the excellent library from your Java applications.

Using OpenCV 3.1.0 with Maven

After having compiled opencv like described above, several directories and files had been created. Amongst those, in the 'bin' folder, there is a file called


This jar file can be installed in the local maven repository like this:

mvn install:install-file 

From now on you should be able to reference the library with maven in the pom.xml like this:


Still, in order to get OpenCV to work, you'll need the native part of the library which contains "the real thing" - the Java code is just a thin wrapper which makes it more convenient to call the native code. Those files are generated in the "lib" folder:


One of them is called "" - this library contains the native code for the api which is accessible through the jar file. Make sure this library is loaded before you call the first time into the jar file via 

System.load(new File("/path/to/"))

This should help you start developing against the OpenCV API with Java and MacOsX.

It may happen however, like mentioned, that you will need to install additional software packages such that the compilation step of OpenCV is successful for you.

Friday, December 11, 2015

JavaFX Tableview

In this very short blogpost I'll present you an example for the usage of the JavaFX tableview component.

A JavaFX TableView Screenshot

Yes, the app does not much - it displays some random data in a javafx TableView control. 

The interesting thing maybe is how the table columns are initialized:

I think it is quite obvious what is going on - the columns are somehow connected to the properties of ... erm ... the row entries.

More often than not this is what you want from a tableview, just display some data. 

Consulting javadocs for TableView or TableColumn never hurts, but sometimes it can be a little bit hard to get the big picture, especially when you don't have much experience with JavaFX.

The abstractions provided here help you to display some data quickly (in terms of development time) and can be reused in various scenarios. A self contained project is hosted on my github site, but for the impatient i'll repost the essential parts here as a gist:

Thanks for reading.