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 =;
  font = loadFont("AmericanTypewriter-24.vlw");
  textFont(font, 24);
void draw() {
  Instant end =;
  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 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 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
  • opencv_java320.dll
  • opencv-320.jar

Enjoy and happy coding.


OpenCV 3.1 release Java build

It is the Java build of the new OpenCV 3.1 release. The zipped file contains the Java build for the 64 bit versions of Linux, Mac OSX and Windows. It is available for download at

OpenCV 3.1.0 Java build (64 bit)

Again, you can copy the individual files to your Processing code folder to play with the experiments in this website.

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)
  • (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(""));

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