Skip to content

Instantly share code, notes, and snippets.

@jeonghopark
Created November 27, 2017 18:35
Show Gist options
  • Select an option

  • Save jeonghopark/2593370664470e12c36b762eef4ed9fe to your computer and use it in GitHub Desktop.

Select an option

Save jeonghopark/2593370664470e12c36b762eef4ed9fe to your computer and use it in GitHub Desktop.
Video Buffer Processing
import processing.video.*;
Capture cam;
PImage[] buffer;
int frameNum = 60;
int writeIndex = 0, readIndex = 1;
void setup() {
size(640, 240);
cam = new Capture(this, 640, 480);
cam.start();
buffer = new PImage[frameNum];
}
void draw() {
if (cam.available()) {
cam.read();
image(cam, 0, 0, 320, 240);
buffer[writeIndex] = cam.get();
if (buffer[readIndex] != null) {
image(buffer[readIndex], 320, 0, 320, 240);
}
writeIndex++;
readIndex++;
if (readIndex >= frameNum - 1) {
readIndex = 0;
}
if (writeIndex >= frameNum - 1) {
writeIndex = 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment