To build a robot that draws portraits I need to have a good supply of tools for image processing. The best open source libraries available are the opencv that I would use with Processing.

Unfortunately opencv are available in C + + and python, but not in Java that is the language used in Processing. Luckily some guys  have built some wrappers that allow to use opencv with Processing.

 

Opencv processing library

The most famous library is this: http://ubaa.net/shared/processing/opencv/ which is very well documented. Its installation is simple and works well. But this library  supports only a few commands opencv and doesn’t provide access to thousands of opencv functions.It use QuickTime to perform functions that use the webcam. The commands supported are the most important, however, it is not enough.It allows to write code using opencv in a very simple way, making the primitives opencv a part of Processing language.

For example this is the capture()  function that allocates and initializes resources for reading a video stream from a camera.
import hypermedia.video.*;
OpenCV opencv; //opecv object

void setup() {
size( 320, 240 ); //window size
opencv = new OpenCV( this ); // opencv object
opencv.capture( width, height ); // open video stream
}

void draw() {
opencv.read(); // grab frame from camera
image( opencv.image(), 0, 0 ); } // and display image

not bad! only 10 rows to display the webcam image. The opencv functions are very easy with this library, but the opencv supported is only the 1.0 and the number of the function is very low.

 

JavaCVPro

Luckily there is another library that allows to use the last version of the opencv, the 2.3.1: JavacvPro.
The documentation for this library is only in French.I understandFrench well, so I have no problems! 🙂

This library implements natively over 100 opencv functions, making them part of the language Processing. In addition it use the library GSVideo which is the official video library for the version 2.0 of Processing.

The use of the library is very simple. This is an example of syntax of the function of edge detection of the original opencv:

cvCanny (opencv_core.CvArr image, opencv_core.CvArr edges, double threshold1, double threshold2, int aperture_size)

this is the corresponding on JacaCvPro in Processing:

canny (PImage image)

The library takes care of the rest! not bad right?  But how does work the processing wrapping in opencv? Opencv is a library written in C + +, Processing works in Java.
JavaCvPro uses another library , javacv, which implements almost all the OpenCV functions directly in Java. Moreover, there is another library, javacpp, which implemets the real link between Java and C++.

So, the chain among libraries is:

Processing —> JavaCvPro —> javacv —> javacpp- –> OpenCV

Difficult? No, easy!

In the next post I show how install opencv and JavaCvPro in windows 7 environment.