/** Reduce resolution of captured image. * @author Mithat Konar */ import processing.video.*; Capture cam; // The video capture device. PImage img; // Buffer image. // Canvas parameters final int CANVAS_WIDTH = 320; final int CANVAS_HEIGHT = 240; final int CANVAS_FPS = 4; // Video capture parameters (adjust as neeeded for your // platform's available capture options): final int CAM_WIDTH = 320; final int CAM_HEIGHT = 240; final int CAM_FPS = 15; // Rendering parameters: number of cells the rendered // image should be in each direction: final int REDUCED_WIDTH = 128; final int REDUCED_HEIGHT = 96; void setup() { frameRate(CANVAS_FPS); size(CANVAS_WIDTH, CANVAS_HEIGHT); if (Capture.list().length == 0) { println("There are no cameras available for capture."); exit(); } // Instantiate a buffer image used for subsampling, etc. img = createImage(REDUCED_WIDTH, REDUCED_HEIGHT, RGB); // Instantiate a new Capture object, requesting the specs: cam = new Capture(this, CAM_WIDTH, CAM_HEIGHT, CAM_FPS); cam.start(); // In Processing 2.0, you need to start the capture device } void draw() { // Grab a frame if (cam.available() == true) { cam.read(); } // The following should work but doesn't. // cam.resize(REDUCED_WIDTH, REDUCED_HEIGHT); // So we use an interim buffer image instead: img.copy(cam, 0, 0, CAM_WIDTH, CAM_HEIGHT, 0, 0, REDUCED_WIDTH, REDUCED_HEIGHT); // And draw the image (full canvas): image(img, 0, 0, width, height); filter(GRAY); // Render image() in B&W. }