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.

63 lines
1.6 KiB
Java

import processing.core.*;
import processing.video.*;
import static processing.core.PApplet.*;
class Camera {
/*
Camera controller.
This class is mostly a wrapper around processing.video.Capture.
*/
// Camera from which we want to update
Capture cam;
// The latest image we got from the camera
PImage latestImage;
Camera(PApplet applet, int cameraMode) {
/*
Initialize a camera.
If you don't know what to set cameraMode to, just set it to 0
and then look at the output; this function prints out a list
of [cameraMode "1920x1080 60fps"] lines which you can use
to choose the mode you want.
*/
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;
}
}