OpenCV 3.4.2 Java Build

After the release of OpenCV 3.4.2, I have prepared the pre-built version of the Java libraries for OSX, Ubuntu, and Windows 8.1 platforms (64 bits).  In this release, there is more extensive support for the Java binding. I also packaged the library as the Processing library – CVImage. Please refer to latest book for details. In addition to the optflow contributed library, it also includes additional contributed libraries, such as bgsegm, face, and tracking.

CVImage for OpenCV 3.4.2

 

Java and time with Processing

Instead of using the Processing millis() function or the Java Timer class, we can also make use of the relatively new Instant and Duration classes in Java 8. Here is one simple example for demonstration.

The program uses 2 Instant variables: start, end. It computes the time duration between them using the Duration.between() function.

import java.time.Instant;
import java.time.Duration;
 
Instant start;
PFont font;
 
void setup() {
  size(640, 480);
  start = Instant.now();
  frameRate(30);
  font = loadFont("AmericanTypewriter-24.vlw");
  textFont(font, 24);
}
 
void draw() {
  background(0);
  Instant end = Instant.now();
  Duration elapsed = Duration.between(start, end);
  long ns = elapsed.toNanos();
  text(Long.toString(ns), 230, 230);
}

 

OpenCV 3.2 Java Build

In preparing for the forthcoming book in Processing and OpenCV, I have tried to build the Java binding in OpenCV 3.2. It worked easily for the basic components. Nevertheless, when I included the contribution moduleoptflow, it failed. After a number of attempts in various platforms, I found it was due to the gen_java.py script in folder opencv-3.2.0/modules/java/generator. I tried to add back the import details for the class DenseOpticalFlow. It worked again. Here is what I patch in the gen_java.py script.

For those who do not want to build it yourselves, you can download a pre-built version of the OpenCV 3.2 Java library. You can use it with Processing immediately. I have tested it with the current Processing at 3.3. It contains the following files for various platforms in 64 bit:

  • libopencv_java320.dylib
  • libopencv_java320.so
  • opencv_java320.dll
  • opencv-320.jar

Enjoy and happy coding.

 

OpenCV 3.0.0 rc1 Java build

I built the OpenCV 3.0.0 rc1 64-bit Java bindings and packaged into one single file. You can use it for the Processing examples. Copy them to the code folder of the sketch for simple testings.

opencv_java300_rc1 (64-bit)

It includes the following files,

  • opencv-300.jar
  • libopencv_java300.dylib (patched with the @loader_path)
  • libopencv_java300.so (built in Ubuntu 64 bit)
  • opencv_java300.dll (default one from the pre-built binary)

Telling 32-bit or 64-bit in Java

Here is a short tip to check whether the current machine (JVM) is running 32 bit or 64 bit in Java and thus Processing.
 

int arch = Integer.parseInt(System.getProperty("sun.arch.data.model"));

 
The integer variable arch will give either 32 or 64 depending on the JVM.