processing:video_capture
This is an old revision of the document!
Table of Contents
Video Capture Examples
The following have been adapted from the Processing 2.0 library reference and from examples at Learning Processing.
List available capture devices
- list_capture_devices.pde
/** Print out a list of available capture (i.e., video) devices * @author Mithat Konar */ import processing.video.*; Capture cam; void setup() { String[] cameras = Capture.list(); if (cameras.length == 0) { println("There are no cameras available for capture."); exit(); } println("Available cameras:"); for (int i = 0; i < cameras.length; i++) { println("camera " + i + ": " + cameras[i]); } }
Show video
By requesting capture parameters
- show_capture_by_parameters.pde
/** Show video using requested capture parameters * @author Mithat Konar */ import processing.video.*; Capture cam; final int CAM_WIDTH = 320; final int CAM_HEIGHT = 240; final int FPS = 15; void setup() { size(CAM_WIDTH, CAM_HEIGHT); if (Capture.list().length == 0) { println("There are no cameras available for capture."); exit(); } // Instantiate a new Capture object, requesting the specs: cam = new Capture(this, CAM_WIDTH, CAM_HEIGHT, FPS); cam.start(); // In Processing 2.0, you need to start the capture device } void draw() { if (cam.available() == true) { cam.read(); } image(cam, 0, 0); }
By specifying device
Note that Processing will crop the capture to the canvas size if it doesn't fit.
- show_capture_by_devnum.pde
/** Show video using specified capture device * @author Mithat Konar */ import processing.video.*; Capture cam; final int CANVAS_WIDTH = 320; final int CANVAS_HEIGHT = 240; final int camnum = 55; // Pick a camnum that makes sense given the canvas size! void setup() { size(CANVAS_WIDTH, CANVAS_HEIGHT); String[] camera_list = Capture.list(); if (camera_list.length == 0) { println("There are no camera_list available for capture."); exit(); } println("Available cameras:"); for (int i = 0; i < camera_list.length; i++) { println("camera " + i + ": " + camera_list[i]); } println(); println("Using camera " + camnum + ", " + camera_list[camnum] + "."); // Instantiate a Capture object by specifying the device name stored // in camera_list array: cam = new Capture(this, camera_list[camnum]); cam.start(); // In Processing 2.0, you need to start the capture device } void draw() { if (cam.available() == true) { cam.read(); } image(cam, 0, 0); }
processing/video_capture.1365726715.txt.gz · Last modified: 2013/04/12 00:31 by mithat