Hey !
I want to draw on a screen, an average frame using formula like this: aFrame = 0.99aFrame + 0.01CurrentFrame; (CurrentFrame is an actual frame taken from cam).
Ofcourse at the beginning "aFrame" contain diffrent value but with each iteration (new frame loaded) it its closer to CurrentFrame value. After about 10-30 (considering we are using 30 fps camera and the image is static) aFrame should be equal to CurrentFrame and we should get picture like this:
Instead, what I get is this:
Here is a simple code. What is wrong with these calculations ? Why aren't the rc,gc,bc values getting closer to current frame values ?
import processing.video.*;
import processing.serial.*;
Capture video;
Serial myPort;
void setup()
{
size(640, 480);
video = new Capture(this, width, height, 30);
video.start();
}
void captureEvent(Capture video)
{
video.read();
}
void draw()
{
video.loadPixels();
image(video, 0, 0);
loadPixels();
float rc = 0; // Initialaizing values are 0, so at the start, strange thinks may display
float gc = 0;
float bc = 0;
for (int x = 0; x < video.width; x++ )
{
for (int y = 0; y < video.height; y++ )
{
int loc = x + y * video.width;
color currentColor = video.pixels[loc]; //current values, taken from cam
float r3 = red(currentColor);
float g3 = green(currentColor);
float b3 = blue(currentColor);
rc = rc*0.99 + r3*0.01; //with each iterations, rc,gc,bc values are closer to current frame
gc = gc*0.99 + g3*0.01; //so after some time, these values will be almost equal to current r3, g3, b3
bc = bc*0.99 + b3*0.01;
pixels[loc] = color(rc,gc,bc); //I am drawing the values on screen, after some time, I should get clear a clear picture.
}
}
updatePixels();
}