Skip to content

Instantly share code, notes, and snippets.

@jeonghopark
Created November 27, 2017 18:35
Show Gist options
  • Save jeonghopark/2593370664470e12c36b762eef4ed9fe to your computer and use it in GitHub Desktop.
Save jeonghopark/2593370664470e12c36b762eef4ed9fe to your computer and use it in GitHub Desktop.

Revisions

  1. jeonghopark created this gist Nov 27, 2017.
    33 changes: 33 additions & 0 deletions video_buffer.pde
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    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;
    }
    }
    }