mirror of
https://github.com/processing/processing4.git
synced 2026-01-29 19:31:16 +01:00
Updated capture examples
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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++;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user