Updated capture examples

This commit is contained in:
codeanticode
2012-08-15 22:18:15 +00:00
parent a406170c1e
commit 26e6038f61
2 changed files with 15 additions and 23 deletions

View File

@@ -22,19 +22,10 @@ void setup() {
println(cameras[i]);
}
cam = new Capture(this, 320, 240, cameras[0]);
cam.start();
// You can get the list of resolutions (width x height x fps)
// supported capture device by calling the resolutions()
// method. It must be called after creating the capture
// object.
Resolution[] res = cam.resolutions();
println("Supported resolutions:");
for (int i = 0; i < res.length; i++) {
println(res[i].width + "x" + res[i].height + ", " +
res[i].fps + " fps (" + res[i].fpsString +")");
}
// The camera can be initialized directly using an element
// from the array returned by list():
cam = new Capture(this, cameras[0]);
cam.start();
}
}
@@ -46,4 +37,4 @@ void draw() {
// The following does the same, and is faster when just drawing the image
// without any additional resizing, transformations, or tint.
//set(0, 0, cam);
}
}

View File

@@ -19,7 +19,7 @@ void setup() {
size(600, 400, P2D);
// Uses the default video input, see the reference if this causes an error
video = new Capture(this, 160, 120);
video = new Capture(this, 320, 240);
video.start();
maxRows = height * 2;
@@ -34,6 +34,14 @@ void setup() {
void draw() {
video.loadPixels();
arraycopy(video.pixels, 0, buffer, writeRow * width, width);
writeRow++;
if (writeRow == maxRows) {
writeRow = 0;
}
topRow++;
for (int y = 0; y < height; y++) {
int row = (topRow + y) % maxRows;
arraycopy(buffer, row * width, g.pixels, y*width, width);
@@ -44,11 +52,4 @@ void draw() {
void captureEvent(Capture c) {
c.read();
c.loadPixels();
arraycopy(c.pixels, 0, buffer, writeRow * width, width);
writeRow++;
if (writeRow == maxRows) {
writeRow = 0;
}
topRow++;
}
}