mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
Updates for video capture examples, new keywords.txt
This commit is contained in:
@@ -16,42 +16,47 @@ ArrayList frames = new ArrayList();
|
||||
|
||||
void setup() {
|
||||
size(640, 480);
|
||||
video = new Capture(this, width, height, 30);
|
||||
video.start();
|
||||
|
||||
// This the default video input, see the GettingStartedCapture
|
||||
// example if it creates an error
|
||||
video = new Capture(this, width, height);
|
||||
|
||||
// Start capturing the images from the camera
|
||||
video.start();
|
||||
}
|
||||
|
||||
void captureEvent(Capture camera) {
|
||||
camera.read();
|
||||
|
||||
//copy the current video frame into an image, so it can be stored in the buffer
|
||||
// Copy the current video frame into an image, so it can be stored in the buffer
|
||||
PImage img = createImage(width, height, RGB);
|
||||
video.loadPixels();
|
||||
arrayCopy(video.pixels, img.pixels);
|
||||
|
||||
frames.add(img);
|
||||
|
||||
//once there are enough frames, remove the oldest one when adding a new one
|
||||
// Once there are enough frames, remove the oldest one when adding a new one
|
||||
if (frames.size() > height/4) {
|
||||
frames.remove(0);
|
||||
}
|
||||
}
|
||||
|
||||
void draw() {
|
||||
//set the image counter to 0
|
||||
// Set the image counter to 0
|
||||
int currentImage = 0;
|
||||
|
||||
loadPixels();
|
||||
|
||||
//begin a loop for displaying pixel rows of 4 pixels height
|
||||
// Begin a loop for displaying pixel rows of 4 pixels height
|
||||
for (int y = 0; y < video.height; y+=4) {
|
||||
//go through the frame buffer and pick an image, starting with the oldest one
|
||||
// Go through the frame buffer and pick an image, starting with the oldest one
|
||||
if (currentImage < frames.size()) {
|
||||
PImage img = (PImage)frames.get(currentImage);
|
||||
|
||||
if (img != null) {
|
||||
img.loadPixels();
|
||||
|
||||
//put 4 rows of pixels on the screen
|
||||
// Put 4 rows of pixels on the screen
|
||||
for (int x = 0; x < video.width; x++) {
|
||||
pixels[x + y * width] = img.pixels[x + y * video.width];
|
||||
pixels[x + (y + 1) * width] = img.pixels[x + (y + 1) * video.width];
|
||||
@@ -60,7 +65,7 @@ void draw() {
|
||||
}
|
||||
}
|
||||
|
||||
//increase the image counter
|
||||
// Increase the image counter
|
||||
currentImage++;
|
||||
|
||||
} else {
|
||||
@@ -70,7 +75,7 @@ void draw() {
|
||||
|
||||
updatePixels();
|
||||
|
||||
//for recording an image sequence
|
||||
// For recording an image sequence
|
||||
//saveFrame("frame-####.jpg");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user