Created
July 18, 2013 18:19
-
-
Save gregtemp/6031630 to your computer and use it in GitHub Desktop.
Video delay - Processing 2.0 - some dood on stack overflow made this for me when I posted my version that didn't work.
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 w = 320; | |
int h = 240; | |
int nFrames = 30; | |
int iWrite = 0, iRead = 1; | |
void setup(){ | |
size(w, h); | |
cam = new Capture(this, w, h); | |
cam.start(); | |
buffer = new PImage[nFrames]; | |
} | |
void draw() { | |
if(cam.available()) { | |
cam.read(); | |
buffer[iWrite] = cam.get(); | |
if(buffer[iRead] != null){ | |
image(buffer[iRead], 0, 0); | |
} | |
iWrite++; | |
iRead++; | |
if(iRead >= nFrames-1){ | |
iRead = 0; | |
} | |
if(iWrite >= nFrames-1){ | |
iWrite = 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment