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 & HelpPrograms › Re: playing slideshow while taking pictures
Pages: 1 2 
Re: playing slideshow while taking pictures (Read 7118 times)
Re: playing slideshow while taking pictures
Reply #15 - Jun 10th, 2010, 4:35am
 
No...

Well, I cannot test your code, so I give theoretical answers that might not work (or even not compile!).
The base idea is (with patches):
Code:
// Global variable
String path = "/Users/menno/Documents/Processing/picture_pool/";
// [...]

 if (pictureJustTaken == false && faces.length >= 1) {
   String fileName = "faces" + year() + "-" + month() + "-"  + day() + " "  + hour() + "."  + minute() + "."  + second() + ".jpg";
   File ff = new File(path + "_" + fileName);
   save(ff.getAbsolutePath()); // Long operation
   // Rename on the fly
   ff.renameTo(new File(path + fileName));
   pictureJustTaken = true;
   startTimer = millis();
   println(frame);
 }
(I changed to a folder outside of the sketches, for simplicity and to allow changing names...)
Code:
// Global variable
String path = "/Users/menno/Documents/Processing/picture_pool/";
// [...]

void loadFilenames() {
 File folder = new File(path);
 FilenameFilter imgFilter = new FilenameFilter() {
   boolean accept(File dir, String name) {
 return !name.startsWith("_") &&
(name.toLowerCase().endsWith(".jpg") ||
name.toLowerCase().endsWith(".png"));
   }
 };
loadFilenames = folder.list(imgFilter);
}
Re: playing slideshow while taking pictures
Reply #16 - Jun 10th, 2010, 4:54am
 
allright, taking the pricture program works. He puts the pictures in the 'pool'

I'm guess something goed wrong with the path. and I tried to put 'path' on the place of the path where it is right now.

But in the slideshow I added the code and I get an null pointer exception on this highlighted line:

Code:
void loadPhotos() {
for (int i = 0; i < loadFilenames.length; i++) {
if (!loadedFileNames.contains(loadFilenames[i])) {
loadPhotos[i] = loadImage("/Users/menno/Documents/Processing/taking_pics/" + loadFilenames[i]);
loadedFileNames.add(loadFilenames[i]);
}
}
}
Re: playing slideshow while taking pictures
Reply #17 - Jun 10th, 2010, 6:33am
 
I forgot the line: loadFilenames = folder.list(imgFilter); (added above)
Re: playing slideshow while taking pictures
Reply #18 - Jun 10th, 2010, 8:09am
 
If I add the line it should look like this right?

Code:
void loadPhotos() {
loadFilenames = folder.list(imgFilter);
for (int i = 0; i < loadFilenames.length; i++) {
if (!loadedFileNames.contains(loadFilenames[i])) {
loadPhotos[i] = loadImage("/Users/menno/Documents/Processing/picture_pool/" + loadFilenames[i]);
loadedFileNames.add(loadFilenames[i]);
}
}
}


It now says ' cannot find anything named 'folder'' And he probably also doesn;t find imgFilter. Do I need to set something up in the global?
Re: playing slideshow while taking pictures
Reply #19 - Jun 10th, 2010, 8:15am
 
The line goes in loadFilenames(), as I shown above (ie. I fixed my previous message #15)
Re: playing slideshow while taking pictures
Reply #20 - Jun 10th, 2010, 10:00am
 
All right, tuning into the discussion again Smiley

I wrote the programs on two different computers, cause I only have a webcam on my EEE, so I had not tested it as a combination. I have tried copying full images into the directory while the slideshow program was running though and this worked without problem.

Like PhiLho said before, I think the current problem with half images etc. is that the image is still being saved by one program (webcamsnaps) while the other starts loading it (slideshow). In addition to the temporary rename suggestion I see two other possible solutions:

1. Delay the time between seeing/loading the filename and loading the actual file. This in order to give the webcamsnaps program more time to fully save the file.

2. Integrate both programs into one program. Two individual programs is great for two computers. And btw this started as two different threads. But you said somewhere that you're now running both on the same computer. So integrating the two might be a better idea and also prevent problems like this.

So those are ideas. With regard to implementation. As you might have guessed from my absence, I'm short on time. Both due to work and personal projects. So I don't know when I will have time to take a closer look at this.
Re: playing slideshow while taking pictures
Reply #21 - Jun 11th, 2010, 1:35am
 
Philho,

It seems to load fine right now. But after 4 or 5 images the program seems to crash (stops). I highlighted the error.

Exception in thread "Animation Thread" java.lang.NullPointerException
     at processing.core.PGraphics.image(PGraphics.java:2197)
     at processing.core.PApplet.image(PApplet.java:7286)
     at slideshow$Photo.display(slideshow.java:151)
     at slideshow.draw(slideshow.java:59)
     at processing.core.PApplet.handleDraw(PApplet.java:1425)
     at processing.core.PApplet.run(PApplet.java:1327)
     at java.lang.Thread.run(Thread.java:613)
Re: playing slideshow while taking pictures
Reply #22 - Jun 11th, 2010, 4:26am
 
He Amnon,

It's a shame (but I understand) that you don't have the time to take a look. It needs to be finished before sunday :S. And just a few small things need to be done.

I hope philho wakes up soon. It's almost there!!!

Thanks so far for all your help!
Re: playing slideshow while taking pictures
Reply #23 - Jun 11th, 2010, 6:07am
 
I am awake, but I have no idea about your error.
Actually, it looks like an excerpt of the previously reported errors (#8).
You no longer have the "Premature end of JPEG file" error?
Maybe you just have a null PImage.
I haven't checked the whole code, but a quick workaround might be to do:
Quote:
void display() { // In Photo class
   if (photo == null) return;
   // [...] remainder of code unchanged
 }
Re: playing slideshow while taking pictures
Reply #24 - Jun 11th, 2010, 8:42am
 
Note: my guard line was intended to be at the start of display()...
But it was a good idea to give the current state of the code, I saw I made a stupid loadPhotos() function...

Since you got code that doesn't rely actually on webcam, I could test it just by adding images to the watched dir. I made a number of small changes:
Code:
import processing.opengl.*;

ArrayList photos = new ArrayList();
String[] fileNameList;
PImage[] loadedPhotos;
int counter, fileCount, imageCount;
boolean autoPlay = true; // by default autoplay is OFF
HashSet loadedFileNames = new HashSet();
String path = "/Users/menno/Documents/Processing/picture_pool/";

void setup() {
size(1024,768,OPENGL);
//size(screen.width,screen.height,OPENGL); // full screen mode
smooth();
loadedPhotos = new PImage[100]; // maximum of 10.000 images
loadFileNames();
loadPhotos(); // all existing images are loaded in setup
fileCount = fileNameList.length;
}

void draw() {
background(51);
checkNew(); // checks for new images in the data directory every draw cycle
if(autoPlay) autoPlay();
Photo lastPhoto = null;
for (int i = 0; i < photos.size(); i++) {
Photo s = (Photo) photos.get(i);
s.display();
s.move();
lastPhoto = s;
}
if (lastPhoto != null && lastPhoto.bStopped && photos.size() == fileCount) {
// reset slideshow when it reaches the last slide which stopped to move
photos.clear();
loadPhotos();
}
}

void loadFileNames() {
File folder = new File(path);
FilenameFilter imgFilter = new FilenameFilter() {
public boolean accept(File dir, String name) {
return !name.startsWith("_") &&
(name.toLowerCase().endsWith(".jpg") ||
name.toLowerCase().endsWith(".png"));
}
};
fileNameList = folder.list(imgFilter);
}

void loadPhotos() {
for (int i = 0; i < fileNameList.length; i++) {
if (!loadedFileNames.contains(fileNameList[i])) {
// A new file!
loadedPhotos[imageCount++] = loadImage(path + fileNameList[i]);
loadedFileNames.add(fileNameList[i]);
}
}
}

void checkNew() {
loadFileNames();
if (fileNameList.length > fileCount) {
loadPhotos(); // only call loadPhotos if there are new images
fileCount = fileNameList.length;
}
}


void autoPlay() {
counter++;
if (counter >= 60 && photos.size() < imageCount)
{
photos.add(new Photo(random(80,width-80),random(60,height-60),random(-30,30)));
counter=0;
}
}

void keyPressed() {
if (key == 'z') {if(autoPlay) autoPlay = false; else autoPlay = true;}
if (key == ' ') {if (photos.size() < imageCount) {photos.add(new Photo(random(80,width-80),random(60,height-60),random(-30,30)));}}
if (key == 'x') {if (photos.size() > 0) {photos.remove(photos.size()-1);}}
if (key == 'c') {photos.clear();}
}

class Photo {
PImage photo;
float targetXpos;
float targetYpos;
float rotation;
float xpos;
float ypos;
float easing;
boolean bStopped;

Photo(float targetXposTemp, float targetYposTemp, float rotationTemp) {
photo = loadedPhotos[photos.size()];
xpos = width/2;
ypos = -130;
targetXpos = targetXposTemp;
targetYpos = targetYposTemp;
rotation = rotationTemp;
easing = 0.1;
}

void display() {
rectMode(CENTER);
imageMode(CENTER);
noStroke();

pushMatrix();

translate(width/2,height/2);
rotate(radians(rotation));
translate(-width/2,-height/2);

translate(xpos,ypos);

fill(0,0,0,50);
rect(4,4,330,250);
fill(255,255,255);
rect(0,0,330,250);
image(photo,0,0,320,240);

popMatrix();
}

void move() {
if (bStopped) return;
if (dist(xpos,ypos,targetXpos,targetYpos) > 1) { // only move if the destination has not been reached
xpos = (1-easing) * xpos + (easing) * targetXpos;
ypos = (1-easing) * ypos + (easing) * targetYpos;
} else {
bStopped = true;
}
}
}

Seems to work OK for my limited testing.
Re: playing slideshow while taking pictures
Reply #25 - Jun 11th, 2010, 12:56pm
 
Wow, Really great. I've been testing it for a while now. And it seems to work perfect this time. Smiley You're great!!!

You helped a guy graduating Smiley Off course this is a part of the project and I wont take credit for it. Tongue

Now I've time to tweak it. There're some features I want to incorparate but their not nessecery for the presentation.

I want to add something that he only reads the last 20 (or 30) NEW images.

Do you have a thread that will help me further?

Thanks so far!!

Re: playing slideshow while taking pictures
Reply #26 - Jun 12th, 2010, 7:38am
 
Here I'm AGIAN with a question! Cheesy

Yesterday I tested it on my mac book pro and it seemed to work fine with memory etc. But now I've tested the whole installation on an Imac (white with 2GB memory) and it seems that it runs out of memory after a while (20 pics) and crashes . I increased the memory in the prefrences (didn't help)
Is there a way to clear the memory after every run?

And this line not seems to work. I tried to put it to 20 but whem he reaches the 20 slides (pics) it stops and gifs an out of bounce error.





Re: playing slideshow while taking pictures
Reply #27 - Jun 12th, 2010, 8:56am
 
It is normal to run out of memory if you load lot of big photos. Increasing memory should have helped, although in 32bit Java I think you are limited for the max memory you can allocate (there are several threads on the topic). Since you display the images in limited size, a way to optimize memory usage is to do a PImage.resize() after loading: thus no need to resize on each display, and the images will take less memory overall.

"gifs an out of bounce error"
I suppose it gives an out of bounds error... Did you changed the loadedPhotos size?

To answer your previous question, it is a bit harder to do, because we have to store the time stamp of the files (or use the one in the file name?) to eliminate the oldest images.
Re: playing slideshow while taking pictures
Reply #28 - Jun 13th, 2010, 2:06am
 
I didn't changed the loadedPhotos size!! I've an idea but don't know if it will work.

idea:
If I make a new folder on the computer. and than tell the slideshow script, when the photoCount is 20 move all pictures to the new folder.

Re: playing slideshow while taking pictures
Reply #29 - Jun 13th, 2010, 3:35am
 
Good idea, but to keep things simple in the slideshow and keep tasks separated, I would give this task to the sketch creating the images.
Pages: 1 2