You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.1 KiB
Java

8 years ago
import processing.core.*;
import processing.video.*;
import static processing.core.PApplet.*;
8 years ago
class Camera {
Capture cam;
PImage latestImage;
8 years ago
/*
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.");
8 years ago
applet.exit();
} else {
println("Available cameras:");
8 years ago
for(int i = 0; i < cameras.length; i++) {
println(i, cameras[i]);
8 years ago
}
print("Using camera mode ");
println(cameras[cameraMode]);
8 years ago
this.cam = new Capture(applet, cameras[cameraMode]);
this.cam.start();
latestImage = cam; //initialize unconditionally
8 years ago
}
}
8 years ago
boolean updateImage() {
boolean newImageAvailable = cam.available();
if (newImageAvailable) {
cam.read();
8 years ago
latestImage = cam;
8 years ago
}
return newImageAvailable;
}
PImage getImage() {
8 years ago
return latestImage;
8 years ago
}
8 years ago
}