To use the OpenCV 2.3.1 in Processing  the shortest and easiest way is to use the JavaCvPro by X.Hinault.
The library JavaCVPro allows to use the OpenCV primitives in a very simple and immediate.
To use the webcam, it requires the library GSVideo  that can be installed in Processing / modes / java / libraries (for Processing 1.5).

Here’s an example of JavaCVPro usage:

// Programme d'exemple de la librairie javacvPro
// par X. HINAULT - octobre 2011
// Tous droits réservés - Licence GPLv3

// Exemple fonction contrast()

import monclubelec.javacvPro.*; // importe la librairie javacvPro

PImage img;

String url="http://www.mon-club-elec.fr/mes_images/online/lena.jpg"; // String contenant l'adresse internet de l'image à utiliser

OpenCV opencv; // déclare un objet OpenCV principal

void setup(){ // fonction d'initialisation exécutée 1 fois au démarrage

        //-- charge image utilisée --- 
        img=loadImage(url,"jpg"); // crée un PImage contenant le fichier à partir adresse web

        //--- initialise OpenCV ---
        opencv = new OpenCV(this); // initialise objet OpenCV à partir du parent This
        opencv.allocate(img.width, img.height); // initialise les buffers OpenCv à la taille de l'image

        opencv.copy(img); // charge le PImage dans le buffer OpenCV

        //--- initialise fenêtre Processing 
        size (opencv.width()*2, opencv.height()); // crée une fenêtre Processing de la 2xtaille du buffer principal OpenCV
        //size (img.width, img.height); // aalternative en se basant sur l'image d'origine

        //--- affiche image de départ --- 
        image(opencv.getBuffer(),0,0); // affiche le buffer principal OpenCV dans la fenêtre Processing

        //--- opérations sur image ---
        opencv.contrast(+50); // applique réglage contraste sur le buffer principal OpenCV

        //--- affiche image finale --- 
        image(opencv.getBuffer(),opencv.width(),0); // affiche le buffer principal OpenCV dans la fenêtre Processing

       noLoop(); // stop programme 
}

void  draw() { // fonction exécutée en boucle

}


The code is very simple. All the opencv instructions are called simply using ‘opencv.’ before the real instruction. You can use the opencv instructions translated in Processing by X. Hinault in the JavaCvPro libraries.

But it is very interesting to mix OpenCv instruction supported by JavaCvPro libraries and native OpenCv instructions. The JavaCvPro allow to use also the native OpenCV instruction. This is a powerful tool!!!

In the example below, only native
OpenCV instructions are used.

// Example of using native OpenCVPro instruction in Processing
// Robottini.altervista.org
// example by X.Hinault modified
// Licence GPLv3

// Bilinear filter example

import com.googlecode.javacv.*;
import com.googlecode.javacv.cpp.*;
import monclubelec.javacvPro.*;
import java.awt.image.BufferedImage;
PImage imgDest, OrigImg;
void setup() {
  size(640, 240);
  String cheminFichier="C:/Users/Nane/Dropbox/Sorgenti Arduino/Jarkman/Foto/gioconda1.jpg";; 
  OrigImg=loadImage(cheminFichier,"jpg"); 
  //---- appel direct des fonctions de la librairie javacv ---- 
  //--- chargement d'un fichier image 
  opencv_core.IplImage opencvImgSrc= opencv_highgui.cvLoadImage(cheminFichier);

  opencv_core.CvSize mySize=opencvImgSrc.cvSize(); // récupère la taille de l'image 

  opencv_core.IplImage opencvImgDest= opencv_core.cvCreateImage(mySize, opencv_core.IPL_DEPTH_8U, 3); // crée une image IplImage , 3 canaux

  //--- application d'effet opencv ---
 for (int i=0; i<20; i++)
    opencv_imgproc.bilateralFilter(opencvImgSrc, opencvImgDest, 3,120.0, 190.00,1 ); // applique un effet Flou gaussien 

//============ récupérer une image openCV dans Processing ===== 
  //--- récupérer l'objet IplImage dans un BufferedImage 
  BufferedImage bufImg=opencvImgDest.getBufferedImage(); // récupère l'image

  //---- créer un PImage --- 
  PImage img = createImage(320,240, PConstants.RGB); 

  // charge les pixels de l'image buffer dans img.pixels
  bufImg.getRGB(0, 0, 320, 240, img.pixels, 0, 320); 
  img.updatePixels();
  image(OrigImg,0,0); 
  image(img,320,0); // affiche l'image
}
void draw() {

}


In this case the OpenCv instructions for Processing are used only in the last part of the code, in order to show the images. The coding of the native OpenCV instructions is more difficult, but very very powerful. It is possible to use almost the whole set of instructions offered by the OpenCv 2.3.1.