Transferring openCV from C++ to Java

openCV for Java

openCV for Java


Transferring the openCV from c++ to Java is what i am doing recently. Comparing with opencv c++ it feels more natural to programme in Java, because of the way of Object-oriented programming and some of Java’s advantages.

But how can the openCV be used in Java seamlessly?

The easiest way is to take advantage of existing Java openCV projects, such as JavaCV ( or openCV in Java ( These wrappers do make the use of openCV relatively easier, as the face detection example below.

import java.awt.Rectangle;

OpenCV opencv;

void setup() {

    size( 320, 240 );

    opencv = new OpenCV(this);
    opencv.capture( width, height );
    opencv.cascade( OpenCV.CASCADE_FRONTALFACE_ALT );    
    // load the FRONTALFACE description file

void draw() {;
    image( opencv.image(), 0, 0 );

    // detect anything ressembling a FRONTALFACE
    Rectangle[] faces = opencv.detect();

    // draw detected face area(s)
    for( int i=0; i<faces.length; i++ ) {
        rect( faces[i].x, faces[i].y, faces[i].width, faces[i].height ); 
[These lines of codes are from]

Another advantage of using openCV in Java is that it can be integrated into mobile systems such as the Android. With Eclipse the wrapper classes can be used to programme intuitively. For example:

import static com.googlecode.javacv.cpp.opencv_core.*;
import static com.googlecode.javacv.cpp.opencv_imgproc.*;
import static com.googlecode.javacv.cpp.opencv_highgui.*;

public class Smoother {
    public static void smooth(String filename) { 
        IplImage image = cvLoadImage(filename);
        if (image != null) {
            cvSmooth(image, image, CV_GAUSSIAN, 3);
            cvSaveImage(filename, image);

Author: Andol Li

A HCI researcher, a digital media lecturer, an information product designer, and a python/php/java coder.

2 Comments On “ Transferring openCV from C++ to Java”

  1. hi Andol,
    i am Shahrukh Khan from india . I am working on a project which is will recognize hand gestures on the android platform. i figured you might help in a small tutorial on Introduction to javaCV+android. also if this is alot to ask for can you atleast tell me the approach to start using javaCV and hand gesture recognisation. i dont even know how to get the secondary camera feed from the android phone !!
    for ex:
    Thank you in advance (“,)

Leave a comment
Due to technical adjustments, the comment function is shortly closed and will be re-openning soon. Thanks.

Copyrights 2006-2018 © All rights reserved
Theme Tree2, re-designed by Andol Li, powered by WordPress and Bootsrap
WWW.ANDOL.ME | 浙ICP备15040508号-1
公安备案图标 浙公网安备33010602004018号
Back to top