Created
November 27, 2017 18:35
-
-
Save jeonghopark/2593370664470e12c36b762eef4ed9fe to your computer and use it in GitHub Desktop.
Video Buffer Processing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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