Installing the OpenCV library from http://ubaa.net/shared/processing/opencv/
You’ll start by importing the OpenCV library into your sketch. This makes all the functionality of the library available for you to use in your sketch. You need to declare an OpenCV object right before the setup() function, so you can use this object throughout your sketch.
In the setup() function, you need to create an instance of the OpenCV class, using the
OpenCV constructor. This constructor is used with the this keyword as a parameter and
refers to the main PApplet class. The capture() method is used by the openCV object to
access the webcam. The first parameter of this method is the width of the video you want to capture, and the second one is the height. I’ve used the width and height of my Processing sketch, but you can use other numbers.
opencv = new OpenCV( this );
opencv.capture( width, height );
Inside the draw() function, we’ll start by using the read() method. This method grabs a new frame from the webcam. The flip() method is used in this example to mirror the webcam feed. This method can be used with three values: OpenCV.FLIP_HORIZONTAL, OpenCV.
FLIP_VERTICAL, and OpenCV.FLIP_BOTH. The opencv.image() method returns the
current webcam frame as a PImage object, which can be displayed on the screen using the
standard Processing image() function.
opencv.flip( OpenCV.FLIP_HORIZONTAL );
image( opencv.image(), 0, 0 )