Hey,
I'm having a problem with storing the current frame of the camera input and having it played back with a certain delay.
As for now I have three "Images" (the current, one 1 frame delayed and one with a larger delay) which are combined again into one image using each image as a color channel.
The problem is that the images I write into the buffer/array all contain the current frame and not different frames and just the last element (delayPast-1) contains the current frame. I just can't figure out what's wrong, as the delay with just the last frame ist working flawlessly.
I also found this thread http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Video;action=display;num=1159143757
but the code mentioned there doesn't work for me either at least with a capture event, with a movie it does...
Code:
import processing.video.*;
int numPixels;
PImage prevFrame;
int delayPast = 24; //amount of frames to delay
PImage[] pastFrames = new PImage[delayPast];
Capture video;
void setup() {
size(640, 480);
video = new Capture(this, width, height, 24);
numPixels = video.width * video.height;
prevFrame = createImage(video.width, video.height, RGB);
for(int i = 0; i < delayPast; i++){
pastFrames[i] = createImage(video.width, video.height, RGB);
}
}
void draw() {
loadPixels();
if (video.available()) {
video.read();
//shifting the elements of the array to the left
for(int i = 1; i < delayPast; i++) {
pastFrames[i-1] = pastFrames[i];
}
video.loadPixels();
for (int i = 0; i < numPixels; i++) {
color currColor = video.pixels[i];
color prevColor = prevFrame.pixels[i];
color pastColor = pastFrames[0].pixels[i];
//extract the green channel of the realtime video
int currG = (currColor >> 8) & 0xFF;
//extract the blue channel of the 1-frame delayed video
int prevB = prevColor & 0xFF;
//extract the red channel of the 24-frame delayed video
int pastR = (pastColor >> 16) & 0xFF;
//combine all channels to get a "full" RGB result
pixels[i] = color(pastR, currG, prevB);
//pixels[i] = 0xff000000 | (diffR << 16) | (diffG << 8) | diffB;
//current Frame is now the last Frame
prevFrame.pixels[i] = currColor;
//current Frame is attached at the end of the delay array
pastFrames[delayPast-1].pixels[i] = currColor;
}
updatePixels();
}
}