Webcams
I have come a long way from my first taste of processing. Having become comfortable with the code to a certain extent I have moved on from abstract examples of code and am now looking in to using webcams, which is essential for the current project.Processing has several camera presets built in. Using presets is all well and good but knowing how to implement it in to my code is more important. In File > Examples > Library > Video (Capture). The basic one is GettingStartedCapture and thankfully the code is heavily commented, helping me understand how it is working.
/*** Getting Started with Capture.** Reading and displaying an image from an attached Capture device.*/import processing.video.*;Capture cam;void setup() {size(640, 480);// If no device is specified, will just use the default.cam = new Capture(this, 320, 240);// To use another device (i.e. if the default device causes an error),// list all available capture devices to the console to find your camera.//String[] devices = Capture.list();//println(devices);// Change devices[0] to the proper index for your camera.//cam = new Capture(this, width, height, devices[0]);// Opens the settings page for this capture device.//camera.settings();}void draw() {if (cam.available() == true) {cam.read();image(cam, 160, 100);// The following does the same, and is faster when just drawing the image// without any additional resizing, transformations, or tint.//set(160, 100, cam);}}
This sets up a basic stage that displays a camera feed.
OpenCV
Seb has also discussed OpenCV, a set of additional libraries that processor can use to expand it's capabilities. It seems as though OpenCVs ability to manipulate video is more powerful and easier to use than the default processing capabilities and so it is likely that I will use OpenCV for my project.
The OpenCV libraries can be downloaded here: http://opencv.willowgarage.com/wiki/
OpenCV uses 2 important pieces of code at the start:
import hypermedia.video.*;
Imports a video stream.OpenCV opencv;This creates an OpenCV object that can be used to access things in the OpenCV library. In this case the object is called opencv.
After that we need to call the object and use it to display the camera feed, now that it has been imported.
Looking at the code this granularly and having to explain it myself in this blog makes me feel like I am gaining a real understanding of what is going on rather than just passively learning the code.opencv = new OpenCV( this );This initialises the opencv object I made at the top of the sketchopencv.capture( 320, 240 );This uses to OpenCV object to hold the camera feed.
Seb wrote an example code where processing would look for bright areas in the camera feed and spawn particles at that location, which is an interesting concept. It opens up possibilities for using light with interaction.