Hi!
With this little code down there I have tremendous problems, since its juicing out the memory very constantly, which leads to 0 RAM after a while. If I dont run in OpenGL mode, everything is fine!
Besides that, why is it necessary, to make a new image every frame instead of writing to the pixels array of the same image always (line 'PGraphics3 tmp = new PGraphics3(width,height,null);') This also just occurs with OPENGL
Code:
import processing.opengl.*;
import processing.video.*;
Capture camera;
Silhouette sil;
void setup()
{
colorMode(RGB,255);
size(320 ,240, OPENGL);
camera = new Capture(this, width, height, 20);
sil = new Silhouette();
}
void captureEvent(Capture camera)
{
camera.read();
}
void draw()
{
sil.render();
}
class Silhouette
{
int[] pix;
PImage tmp;
Silhouette()
{
pix = new int[width*height];
}
void setValue(int i, int val)
{
pix[i] = val == 0 ? -100 : pix[i] + 15;
}
void render()
{
this.checkInput(camera.pixels);
tmp = new PImage(width,height);
int px;
for (int i=0; i<width*height; i++)
{
px = constrain(pix[i], 0,255);
tmp.pixels[i] = color(px, px, px) ;
}
image(tmp,0,0);
}
void checkInput(color [] video)
{
int threshold = 127;
float p_bri;
for (int i=0; i<video.length; i++)
{
p_bri = brightness (video[i]);
if (p_bri > threshold) sil.setValue(i,1);
else sil.setValue(i,0);// black
}
}
}
Its obvious that the construction of a PImage every frame cant be good...but if you write the "new PImage" code in the class constructor (where I guess it should be) it doesnt work anymore in OPenGL, just if you make a new one every frame. Which fills the Memory until it dies.