euglena/src/Camera.java

45 lines
990 B
Java
Raw Normal View History

2016-07-09 17:16:15 -07:00
import processing.core.*;
import processing.video.*;
class Camera {
Capture cam;
/*
Set up a camera.
*/
Camera(PApplet applet, int cameraMode) {
String[] cameras = Capture.list();
if (cameras.length == 0) {
PApplet.println("There are no cameras available for capture.");
applet.exit();
} else {
PApplet.println("Available cameras:");
for(int i = 0; i < cameras.length; i++) {
PApplet.println(i, cameras[i]);
}
PApplet.print("Using camera mode ");
PApplet.println(cameras[cameraMode]);
this.cam = new Capture(applet, cameras[cameraMode]);
this.cam.start();
}
}
2016-07-09 17:51:24 -07:00
boolean updateImage() {
boolean newImageAvailable = cam.available();
if (newImageAvailable) {
cam.read();
}
return newImageAvailable;
}
Capture getCam() {
return cam;
}
2016-07-09 17:16:15 -07:00
}