import processing.core.*; import processing.video.*; import static processing.core.PApplet.*; class Camera { Capture cam; PImage latestImage; /* Set up a camera. */ Camera(PApplet applet, int cameraMode) { String[] cameras = Capture.list(); if (cameras.length == 0) { println("There are no cameras available for capture."); applet.exit(); } else { println("Available cameras:"); for(int i = 0; i < cameras.length; i++) { println(i, cameras[i]); } print("Using camera mode "); println(cameras[cameraMode]); this.cam = new Capture(applet, cameras[cameraMode]); this.cam.start(); latestImage = cam; //initialize unconditionally } } boolean updateImage() { boolean newImageAvailable = cam.available(); if (newImageAvailable) { cam.read(); latestImage = cam; } return newImageAvailable; } PImage getImage() { return latestImage; } }