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 opencv.org 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

make

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

opencv-310.jar

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

mvn install:install-file 
       -Dfile=opencv-310.jar 
    -DgroupId=org.opencv 
 -DartifactId=opencv-java 
    -Dversion=3.1.0 
  -Dpackaging=jar

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

<dependency>
  <groupId>org.opencv</groupId>
  <artifactId>opencv-java</artifactId>
  <version>3.1.0</version>
</dependency>

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:

libopencv_objdetect.3.1.0.dylib
libopencv_calib3d.3.1.0.dylib
libopencv_objdetect.3.1.dylib
libopencv_calib3d.3.1.dylib
...

One of them is called "libopencv_java310.so" - 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/libopencv_java310.so"))

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.





Sunday, June 21, 2015

Sudoku Capturer Release 1.6

Sudoku Capturer presents itself now as a self contained app, without the need of OpenCV Manager as a separate download.

Carter Buton Album Loan_00115
From a album belonging to barnstormer/daredevil Carter Buton.

I've decided to use the possibility to integrate OpenCV as a native library without the OpenCV Manager functionality since it improves dramatically the user experience for the application.

Many people had been asking themselves why a "third party" dependency had to be installed for the Sudoku Capturer application, and thus I've decided to go the "deprecated" road and link the OpenCV libraries "statically".

In retrospect I should have done this much earlier, since I've learned that I don't have to include every static lib which is offered by OpenCV, I get away with only a subset of those libraries, and the download is in sum even smaller than with the OpenCV Manager.

Since OpenCV is the only native library I need it suffices to copy the libs to the appropriate place and thankfully the android maven plugin does the rest. Sudoku Capturer supports with armeabi-v7a architecture.

About Sudoku Capturer


Sudoku Capturer is an app to solve Sudokus by using your mobile phone camera. The app uses OpenCV and and Scala, and runs on Android. Furthermore a testbed exists which targets JavaFX on the desktop which makes the development process and debugging of the image processing part much more practical than the typical mobile development workflow would ever permit. The whole source code is hosted on GitHub and can be used for your own experiments.