Feedback loop problems w/ camera and projection
in
Core Library Questions
•
2 years ago
First of all, I'd like to praise the versatility of Processing and how amazingly simple it is to quickly apply ideas and secondly I'd like to note that I'm completely new to it.
I'm currently working on a project in which multiple, time-delayed "shadows" are projected onto a canvas. The subject can dance in front of a camera and watch his shadows follow en suite behind him. I've included a crude mock-up and the simple code I've been working with.
My problem stems from the fact that everything black creates a "time-trail". Unfortunately the camera sees the projection as well and this creates a feedback loop (quite frustrating). Does anyone have any suggestions for eliminating this problem?
Thank you in advance,
stef
Original code by rrrufusss, modified by myself (depending on how light/dark it is in your room, you might want to change the THRESHOLD):
I'm currently working on a project in which multiple, time-delayed "shadows" are projected onto a canvas. The subject can dance in front of a camera and watch his shadows follow en suite behind him. I've included a crude mock-up and the simple code I've been working with.
My problem stems from the fact that everything black creates a "time-trail". Unfortunately the camera sees the projection as well and this creates a feedback loop (quite frustrating). Does anyone have any suggestions for eliminating this problem?
Thank you in advance,
stef
Original code by rrrufusss, modified by myself (depending on how light/dark it is in your room, you might want to change the THRESHOLD):
- import processing.video.*;
Capture cam;
VideoBuffer monBuff;
int delay_time = 4; // delay in seconds
int capture_frames = 30; // capture frames per second
void setup() {
size(640, 480, P3D);
monBuff = new VideoBuffer(delay_time*capture_frames, 640, 480);
cam = new Capture(this, 640, 480, capture_frames);
}
void captureEvent(Capture cam) {
cam.read();
monBuff.addFrame( cam );
}
void draw() {
PImage bufimg = monBuff.getFrame();
PImage tmpimg = createImage(bufimg.width,bufimg.height,RGB);
tmpimg.copy(bufimg,0,0,bufimg.width,bufimg.height,0,0,bufimg.width,bufimg.height);
tmpimg.resize(640, 480);
PImage bufimg2 = monBuff.getFrame2();
PImage tmpimg2 = createImage(bufimg2.width,bufimg2.height,RGB);
tmpimg2.copy(bufimg2,0,0,bufimg2.width,bufimg2.height,0,0,bufimg2.width,bufimg2.height);
tmpimg2.resize(640, 480);
PImage bufimg3 = monBuff.getFrame3();
PImage tmpimg3 = createImage(bufimg3.width,bufimg3.height,RGB);
tmpimg3.copy(bufimg3,0,0,bufimg3.width,bufimg3.height,0,0,bufimg3.width,bufimg3.height);
tmpimg3.resize(640, 480);
image( tmpimg, 0, 0 );
blend( tmpimg2, 0, 0, 640, 480, 0, 0, 640, 480, MULTIPLY);
blend( tmpimg3, 0, 0, 640, 480, 0, 0, 640, 480, MULTIPLY);
filter(THRESHOLD, 0.02);
}
class VideoBuffer
{
PImage[] buffer;
int inputFrame = 0;
int outputFrame = 0;
int output2Frame = 0;
int output3Frame = 0;
int frameWidth = 0;
int frameHeight = 0;
/*
parameters:
frames - the number of frames in the buffer (fps * duration)
width - the width of the video
height - the height of the video
*/
VideoBuffer( int frames, int width, int height )
{
buffer = new PImage[frames];
for(int i = 0; i < frames; i++)
{
this.buffer[i] = new PImage(width, height);
}
this.inputFrame = frames - 1;
this.outputFrame = frames -90;
this.output2Frame = frames - 45;
this.output3Frame = frames - 2;
this.frameWidth = width;
this.frameHeight = height;
}
// return the current "playback" frame.
PImage getFrame()
{
int frr;
if(this.outputFrame>=this.buffer.length)
frr = 0;
else
frr = this.outputFrame;
return this.buffer[frr];
}
PImage getFrame2()
{
int frr;
if(this.output2Frame>=this.buffer.length)
frr = 0;
else
frr = this.output2Frame;
return this.buffer[frr];
}
PImage getFrame3()
{
int frr;
if(this.output3Frame>=this.buffer.length)
frr = 0;
else
frr = this.output3Frame;
return this.buffer[frr];
}
// Add a new frame to the buffer.
void addFrame( PImage frame )
{
// copy the new frame into the buffer.
System.arraycopy(frame.pixels, 0, this.buffer[this.inputFrame].pixels, 0, this.frameWidth * this.frameHeight);
// advance the input and output indexes
this.inputFrame++;
this.outputFrame++;
this.output2Frame++;
this.output3Frame++;
// wrap the values..
if(this.inputFrame >= this.buffer.length)
{
this.inputFrame = 0;
}
if(this.outputFrame >= this.buffer.length)
{
this.outputFrame = 0;
}
if(this.output2Frame >= this.buffer.length)
{
this.output2Frame = 0;
}
if(this.output3Frame >= this.buffer.length)
{
this.output3Frame = 0;
}
}
}
1