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 › periodically downloading a webcam image
Page Index Toggle Pages: 1
periodically downloading a webcam image (Read 433 times)
periodically downloading a webcam image
Oct 10th, 2008, 6:39pm
 
I have been playing with processing for months now and am a embedded systems programmer by trade but haven't had a chance to play with processings web capabilities yet.  Yesterday my anniversary trip with my wife was cut by hurricane Norbert and I'd like to save some images from a webcam in Cabo.  Can someone give me a quick example of how I would download and save off an image from a url every minute? My plan is to eventually combine the images into a timelapse video over the next day or two?  The url to the image is:
http://www.allaboutsanjosedelcabo.com/livecam/cabosurfcamnew.jpg
and it is updated once a minute.   Thanks in advance,
Re: periodically downloading a webcam image
Reply #1 - Oct 10th, 2008, 7:32pm
 
Nevermind, I figured it out.  For anyone trying to do this in the future here's my code as an example:

PImage imgA;
int MinCount=0;
int CurrMin;
String urlA = "http://www.allaboutsanjosedelcabo.com/livecam/cabosurfcamnew.jpg";

void setup() {
 size(640,480);
 frameRate(1);
 CurrMin=minute();
 imgA = loadImage(urlA,"jpg");
 image(imgA, 0, 0);
 save("A" + MinCount + ".jpg");
 MinCount+=1;
}

void draw() {
 int m = minute();
 
 if(CurrMin!=m)
 {
   CurrMin=m;
   imgA = loadImage(urlA,"jpg");
   image(imgA, 0, 0);
   save("A" + MinCount + ".jpg");
   MinCount+=1;
 }
}
Re: periodically downloading a webcam image
Reply #2 - Oct 10th, 2008, 9:21pm
 
an even simpler version:

Quote:
String url = "http://www.allaboutsanjosedelcabo.com/livecam/cabosurfcamnew.jpg";
int lastMinute = -1;

void setup() {
  frameRate(1);
}

void draw() {
  int now = minute();
  if (lastMinute != now) {
    // hour as two digits, minute as two digits, then .jpg on the end
    String filename = nf(hour(), 2), nf(now, 2) + ".jpg";
    saveStream(filename, url);
    lastMinute = now;
  }
}



saveStream() is short for loadBytes/loadImage and then saving it directly. even without saveStream, in your code you could write imgA.save(filename) to save it directly, since there's no need to draw it to the screen.

technically i suppose you could set frameRate(1 / 60.0) to have draw() only run once per second, but that seems a little dicey.
Page Index Toggle Pages: 1