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 › Updateing pictures in a grid.
Page Index Toggle Pages: 1
Updateing pictures in a grid. (Read 793 times)
Updateing pictures in a grid.
Feb 10th, 2010, 3:32am
 
Hello.

So I have a folder that I will load pictures from my camera throug the Ardunio board into my computer. So each time there is a new picture in the folder I want to put it in the grid so it will show up like Live feed.

I have found out how to upload pictures from a folder. Thanks to code that was here on the froum.

And that I have manage to make so it will refresh the hole grid system. every x amount of time.

This the code I have so far.

Code:
import processing.pdf.*;

int posterWidth = 875;
int posterHeight = 1225;
int rows = 50;
int colls = 100;

int Check = 10000;
int LastCheck = 0;



void setup()
{
 size(posterWidth, posterHeight);
 beginRecord(PDF, "PIG-###.pdf");

}

void draw(){

 File path= sketchFile("pictures");
 File[] files = path.listFiles();
 
 int imgWidth = posterWidth / rows;
 int imgHeight = posterHeight / colls;

 if(millis() - LastCheck > Check){

   int index = 0;

   for(int y=0; y < colls; y++)
   {
     for(int x = 0; x < rows; x++)
     {
       if(index >= files.length) break;

       PImage img = loadImage(files[index].getAbsolutePath());
       img.resize(imgWidth,imgHeight);
       image(img, x * imgWidth, y * imgHeight);
       println("place @ " + (x * imgWidth));
       index++;
     }
   }

   LastCheck=millis();
 }

 endRecord();
}



This just refreshes the poster about every 2 min, but it takes alot of time to upload the images.

So I was wondering if there is a way to tell the program that if the files that are in the folder now are more then last time then take the new files and upload them in the grid ?
Re: Updateing pictures in a grid.
Reply #1 - Feb 10th, 2010, 5:07am
 
First, you should change the frameRate or put the listFiles in a similar time check (same or more frequently). If there are lot of files, listFiles alone is time consuming.

Second, you should keep the previous result of listFiles. So when the length is different, you can compare both arrays and find out what images are new (or deleted?). Thus you can load only new files.
Of course, it supposes you also keep the previously loaded PImages, to avoid loading them over and over, but beware of memory!
Re: Updateing pictures in a grid.
Reply #2 - Feb 10th, 2010, 9:16am
 
Thank you for the answear.

I have come a litttle further with my code and now it dosen't and just takes the amount of images that is new (but it takes the picture that is last in the folder, but that have worked for me).

But now I have a new problem, because each pictures starts with always at the beginning. But not after the last picture.

I'll put in the code how it looks now.
Code:
import processing.pdf.*;

int posterWidth = 875;
int posterHeight = 1225;
int rows = 50;
int colls = 100;

int Check = 10000;
int LastCheck = 0;
int xoff =0;
int index = 0;



void setup()
{
size(posterWidth, posterHeight);
beginRecord(PDF, "PIG-####.pdf");

}

void draw(){



File path= sketchFile("pictures");
File[] files = path.listFiles();

int imgWidth = posterWidth / rows;
int imgHeight = posterHeight / colls;



if(millis() - LastCheck > Check){


if(files.length > + index){

for(int y=0; y < colls; y++)
{
for(int x = 0; x < rows; x++)
{
if(index >= files.length) break;


PImage img = loadImage(files[index].getAbsolutePath());
img.resize(imgWidth,imgHeight);
image(img, (x * imgWidth) + xoff, y * imgHeight);
println("place @ " + (x * imgWidth));
index++;
xoff = ((x * imgWidth) + imgWidth);
}

index=files.length;
}

}

LastCheck=millis();
}

endRecord();
}


I was trying make xoff to tell the program to start at X place.

And was hoping that makeing

xoff = ((x * imgWidth) + imgWidth);

would change the value of int xoff.

I have no idea what I'm doing wrong, or if there is a better method or even if I'm doing it right
Re: Updateing pictures in a grid.
Reply #3 - Mar 4th, 2010, 10:16am
 
Hi Kaviar,
did you get any further with updating the images to the right place?
I did try your last code snippet and I saw, that it is not working.-
thanks.-

Page Index Toggle Pages: 1