We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Image sequences eating memory
Page Index Toggle Pages: 1
Image sequences eating memory (Read 1954 times)
Image sequences eating memory
Apr 25th, 2005, 9:51pm
 
I've been trying to play with image sequences in OpenGl. when I try to load them in dynamically I notice the PF usage in my Task Manager starting to climb, and the performance starts to stutter. The following code will produce what I'm talking about. You just need to copy the data folder from image sewuence example in to this sketchs data folder to get it to work.


import processing.opengl.*;
String name="PT_Shifty_00";

PImage img;
int head=0;
int frames=38;

void setup(){
size (400,400,OPENGL);


}

void draw(){
background(0);
head++;
head= head%frames;
img=loadImage(name + ((head< 10) ? "0" : "") + head + ".gif");
//beginShape();
image(img,(mouseX-50),(mouseY-50));


}


Im wondering why even though I load images into the same variable, the program continues to eat more and more memory. Is there somewhere else the image data is going.
The point of doing this is to avoid loading an entire movie, instead I can jump from image sequence to image sequence, and have them playing and manipulated in close to realtime

thanks for any help
Re: Image sequences eating memory
Reply #1 - Apr 25th, 2005, 10:01pm
 
don't load images inside draw(), as noted in the loadImage() reference:

http://processing.org/reference/loadImage_.html

"In most cases, load all images in setup() to preload them with the program starts. Loading images in draw() can dramatically reduce the speed of a program."
Re: Image sequences eating memory
Reply #2 - Apr 25th, 2005, 10:09pm
 
The purpose is to be able to skip around different sequences, and not be limmited to what can only fit in memory, so I could have more than a few seconds of sequences.  Is it that possible? I can see the performance hit I take from loading in the draw, wich probably limits my framerate to about 25fps. but once the memory usage climbs high enough it gets worse.
is there somewhere else the image data goes that loading a new image into the same variable dosn't just replace it, but adds to the memory used?
Re: Image sequences eating memory
Reply #3 - Apr 26th, 2005, 1:52am
 
it should be replacing the old memory with the new images, however with java you don't have a lot of control over when the old memory gets freed. the main slowdown will be from the applet pausing while the images load, but the memory should stabilize once it reaches a certain level.

you may try adding framerate() to give the os some breathing room to unload the images.

generally, opengl right now isn't very efficient with image loading and displaying, both speed and memory wise. the problem is that the image is loaded from disk, then stored into a pixel buffer with the data. then gl needs a second full copy of the image which is the next power of 2 larger than your width and height (ie. a 30x60 image becomes 32x128 for opengl) because of how gl handles images.

so you might want to debug first with P3D or the default engine before moving to opengl.
Re: Image sequences eating memory
Reply #4 - Apr 26th, 2005, 7:24am
 
I'm having a similar problem, but with a twist.
This program opens 255 320x240 19.8KB images for a total of about 5Megs of jpegs. Turning a pot connected to an EZIO board allows you to scan back and forth through a little animation. It works fine on my toshiba laptop running linux, but when I tried to run it on one of the Mac G5's at work I got the dreaded "Out of Memory" error. On the laptop I had to set the memory use doo-dah as described in the "out of memory" section of the bugs FAQ. Since it fixed the laptop, I thought it would fix the G5. No such luck. I tried all kinds of permutations on the two values and succeded only in prepetuating the error or locking up the desktop. The program has a println() which tells me that almost all the files load before it bombs.

Frankly I'm stuck.

// This code is mostly cut-and-paste from the
// Processing examples

import processing.net.*;

int data;
int dataIn;
Client client;
int firstFrame = 3120;
int currentFrame = 0;
int numFrames = 256;  // The number of frames in the animation
int frame = 0;
String filenum;
PImage[] images = new PImage[numFrames];
   
void setup()
{
 client = new Client(this, "192.168.1.100", 10001);
 println(client.ip());

 size(320, 240);

 for(int i=0; i<numFrames; i++) {
   currentFrame = firstFrame + i;
   String imageName = "kew_0000" + currentFrame + ".jpg";
   images[i] = loadImage(imageName);
   println(imageName);
 }
}

void draw()
{
if (mousePressed == true){
   client.write('w');
   client.write(1);
   client.write(1);
 }else{
   client.write('w');
   client.write(1);
   client.write(0);
 }
 
 client.write('A');
 client.write(1);
 
 if (client.available() > 0){
   dataIn = client.read();
 }
   image(images[dataIn], 0, 0);
}
Re: Image sequences eating memory
Reply #5 - Apr 27th, 2005, 10:26am
 
Your program will definitely require more than the default amount of memory.

As a rough guide, images will take up width * height
* 4
bytes.  You can find out the maximum allowed memory with:

Code:

println("max mem: " + Runtime.getRuntime().maxMemory());


Are you sure you're setting it correctly on the Mac?
Re: Image sequences eating memory
Reply #6 - May 1st, 2005, 10:17pm
 

 
"you may try adding framerate() to give the os some breathing room to unload the images. " 



I did what  Fry suggested, using framrate() and P3D, and it helped keep the pagefile usage from steadily incresing, although performance still seems to slowly drop at a steady rate, eventually stabilizing.
 

 
"so you might want to debug first with P3D or the default engine before moving to opengl"


I tried using OPENGL with framerate(). The pagefile usage dosnt increase steadily as before. Also the performance is stable, although its still a little slow like id expect.


I have another sketch using OPENGL that loads images and holds about 100 of them in memory replacing one every frame, there might be other bugs in it so I have to take another look at it, but when i use it the page file usage staedily increases until the program crashes. don't know why this happens with this sketch and not the one i mentioned earlier.


I wrote just let you guys know i tried out what you suggested, also to ask if  anyone has suggestions for otherways to get image sequences or videos switching in and out of precessing so I can work with more than a few seconds worth of images. what I have will work for now but I really wish I could get a smoother playback.








Page Index Toggle Pages: 1