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 › 30 Webcam Feeds = Very Slow
Pages: 1 2 
30 Webcam Feeds = Very Slow (Read 3345 times)
30 Webcam Feeds = Very Slow
Dec 10th, 2009, 7:57am
 
Hi, for my final year project I am trying to show around 30 live webcam feeds from around the world. I've got the program working, but it runs incredibly slowly, only refreshing the pictures every 30 seconds or so. Does anybody know how to make the program run faster? I know my coding is not the most streamlined, but I'm new to this!

Here's my code:

PImage a;
PImage b;
PImage c;
PImage d;
PImage e;
PImage f;
PImage g;
PImage h;
PImage i;
PImage j;
PImage k;
PImage l;
PImage m;
PImage n;
PImage o;
PImage p;
PImage q;
PImage r;
PImage s;
PImage t;
PImage u;
PImage v;
PImage w;
PImage x;
PImage y;
PImage z;
PImage a1;

void setup() {
 frameRate(30);
 size(1280, 800);
}

void draw() {
  a = loadImage("http://www.adelaidecitycouncil.com/netcatapps/webcam/images/centralMkt.jpg");
  b = loadImage("http://www.adelaidecitycouncil.com//NetcatApps/webcam/images/bellnth.jpg");
  c = loadImage("http://www.adelaidecitycouncil.com/netcatapps/webcam/images/rundleEast.jpg");
  d = loadImage("http://www.adelaidecitycouncil.com/netcatapps/webcam/images/sk8cam.jpg");
  e = loadImage("http://www.adelaidecitycouncil.com//NetcatApps/webcam/images/bellsth.jpg");
  f = loadImage("http://www.abbeyroad.com/webcam/crossing.jpg?cacheKiller=362683");
  g = loadImage("http://server.fishycam.com/fishycam.jpg?time=1260184950863");
  h = loadImage("http://www.cph.dk/CPHdata/webcam/CPH_spot1.jpg?1260188477647");
  i = loadImage("http://www.adelaidecitycouncil.com/netcatapps/webcam/images/rundle.jpg");
  j = loadImage("http://images.ibsys.com/sea/images/weather/auto/queenannecam_640x480.jpg?");
  k = loadImage("http://www.pani.com/webcam/airport_tower.jpg?");
  l = loadImage("http://www.cph.dk/CPHdata/webcam/CPH_spot3.jpg?1260369631305");
  m = loadImage("http://www.camchickens.com/webcam.jpg");
  n = loadImage("http://www.terrapin-gardens.net/images/webcam.jpg");
  o = loadImage("http://stream.fisheyeview.com/FVCam.jpg");
  p = loadImage("http://www.cs.ualberta.ca/~lake/cam/jpg/large/201.jpg");
  q = loadImage("http://webcams.pancanal.com/webcam/miraflores.jpg");
  r = loadImage("http://www.oceanvillageholidays.co.uk/webcam/ov1.jpg");
  s = loadImage("http://brooklyn-bridge.mobotixcam.de/record/current.jpg?rand=380424");
  t = loadImage("http://www.outercam.co.uk/ssc/camera3.jpg?1260446915311");
  u = loadImage("http://www.xs4all.nl/~twocats/cam/Cam-A.jpg");
  v = loadImage("http://www.sat.dundee.ac.uk/webcam/cam0.jpg");
  w = loadImage("http://facweb.furman.edu/~rbryson/dramadept/TheatreCamPic.jpg");
  x = loadImage("http://www.cbc.ca/bc/webcam/images/webcam.jpg");
  y = loadImage("http://www.outercam.co.uk/ssc/camera2.jpg?1260455145216");
  z = loadImage("http://www.jb.man.ac.uk/common/camera30sec.jpg?dummy=1260456117729");
  a1 = loadImage("http://ecoast.vs.oiccam.com:443/ftp/capcom/jackalope/image.jpg?rand=14:52:10");
 
image(a, 0, 0, (width/6), (height/5));
image(b, (width/6), 0, (width/6), (height/5));
image(c, (width/6)*2, 0, (width/6), (height/5));
image(d, (width/6)*3, 0, (width/6), (height/5));
image(p, (width/6)*4, 0, (width/6), (height/5));
image(r, (width/6)*5, 0, (width/6), (height/5));

image(e, 0, height/5, (width/6), (height/5));
image(f, (width/6), height/5, (width/6), (height/5));
image(g, (width/6)*2, height/5, (width/6), (height/5));
image(h, (width/6)*3, height/5, (width/6), (height/5));
image(o, (width/6)*4, height/5, (width/6), (height/5));
image(s, (width/6)*5, height/5, (width/6), (height/5));

image(q, 0, (height/5)*2, (width/6), (height/5));
image(a, (width/6), (height/5)*2, (width/6), (height/5));
image(b, (width/6)*2, (height/5)*2, (width/6), (height/5));
image(i, (width/6)*3, (height/5)*2, (width/6), (height/5));
image(c, (width/6)*4, (height/5)*2, (width/6), (height/5));
image(t, (width/6)*5, (height/5)*2, (width/6), (height/5));

image(j, 0, (height/5)*3, (width/6), (height/5));
image(k, (width/6), (height/5)*3, (width/6), (height/5));
image(l, (width/6)*2, (height/5)*3, (width/6), (height/5));
image(m, (width/6)*3, (height/5)*3, (width/6), (height/5));
image(n, (width/6)*4, (height/5)*3, (width/6), (height/5));
image(u, (width/6)*5, (height/5)*3, (width/6), (height/5));

image(v, 0, (height/5)*4, (width/6), (height/5));
image(w, (width/6), (height/5)*4, (width/6), (height/5));
image(x, (width/6)*2, (height/5)*4, (width/6), (height/5));
image(y, (width/6)*3, (height/5)*4, (width/6), (height/5));
image(z, (width/6)*4, (height/5)*4, (width/6), (height/5));
image(a1, (width/6)*5, (height/5)*4, (width/6), (height/5));
}
Re: 30 Webcam Feeds = Very Slow
Reply #1 - Dec 10th, 2009, 8:40am
 
it's not running slow, it's just doing a lot - it's loading 30 images every 1/30th of a second. plus a lot of those cameras won't update every 30th of a second so there's no point in checking them so frequently.

better would be to load them all in setup() (which will take a while) and then, every 10 seconds, or so refresh *one* of them in draw().

but first you need to read up on arrays...
Re: 30 Webcam Feeds = Very Slow
Reply #2 - Dec 10th, 2009, 8:41am
 
Please read more about arrays (to clean up your code) and requestImage() to load images in a separate thread.

frameRate(30); means you are trying to load your 27 images 30 times every second : that means, 810 HTTP request and image retrieval each second. This is too high! Try decreasing the frameRate to a reasonable amount.
Re: 30 Webcam Feeds = Very Slow
Reply #3 - Dec 10th, 2009, 9:57am
 
Thanks, well I've tried the requestImage on a sample feed to check it out, but it doesn't refresh it:

     

PImage bigImage;

void setup() {
 size(1280, 800);
 bigImage = requestImage("http://www.adelaidecitycouncil.com//NetcatApps/webcam/images/bellnth.jpg");
}

void draw() {
 if (bigImage.width == 0) {
   // Image is not yet loaded
 } else if (bigImage.width == -1) {
   // This means an error occurred during image loading
 } else {
   // Image is ready to go, draw it
   image(bigImage, 0, 0, width/6, height/5);
 }
}
Re: 30 Webcam Feeds = Very Slow
Reply #4 - Dec 10th, 2009, 11:17am
 
Hi antiplastik, I've tried to use the array & imageRequest functions, but to be honest, I don't understand it at all! Could you give me an example using a part of my code? It would help me so much!
Re: 30 Webcam Feeds = Very Slow
Reply #5 - Dec 10th, 2009, 1:11pm
 
instead of creating alot of different PImages you can create an array of images

like this :

PImage[] images = new PImage[numFrames]; //image array

images[0] = loadImage("1.jpg");
images[1] = loadImage("2.jpg");
images[2] = loadImage("3.jpg");
images[3] = loadImage("4.jpg");  
...

or using a loop if you named your images correctly. but not possible in this case as the url/name is not set by you.

PImage[] images = new PImage[12];
for ( int i = 0; i< images.length; i++ )
{
images[i] = loadImage( i + ".jpg" );   // make sure images "0.jpg" to "11.jpg" exist
}





Re: 30 Webcam Feeds = Very Slow
Reply #6 - Dec 10th, 2009, 1:45pm
 
Okay, I've setup the array of all 30 feeds, but I don't know how to implement it as I've never used it before. So far I have got this:

PImage[] feeds = new PImage[30];

  feeds[0] = loadImage("http://www.adelaidecitycouncil.com/netcatapps/webcam/images/centralMkt.jpg");
  feeds[1] = loadImage("http://www.adelaidecitycouncil.com//NetcatApps/webcam/images/bellnth.jpg");
  feeds[2] = loadImage("http://www.adelaidecitycouncil.com/netcatapps/webcam/images/rundleEast.jpg");
  feeds[3] = loadImage("http://www.adelaidecitycouncil.com/netcatapps/webcam/images/sk8cam.jpg");
  feeds[4] = loadImage("http://www.adelaidecitycouncil.com//NetcatApps/webcam/images/bellsth.jpg");
  feeds[5] = loadImage("http://www.abbeyroad.com/webcam/crossing.jpg?cacheKiller=362683");
  feeds[6] = loadImage("http://server.fishycam.com/fishycam.jpg?time=1260184950863");
  feeds[7] = loadImage("http://www.cph.dk/CPHdata/webcam/CPH_spot1.jpg?1260188477647");
  feeds[8] = loadImage("http://www.adelaidecitycouncil.com/netcatapps/webcam/images/rundle.jpg");
  feeds[9] = loadImage("http://images.ibsys.com/sea/images/weather/auto/queenannecam_640x480.jpg?");
  feeds[10] = loadImage("http://www.pani.com/webcam/airport_tower.jpg?");
  feeds[11] = loadImage("http://www.cph.dk/CPHdata/webcam/CPH_spot3.jpg?1260369631305");
  feeds[12] = loadImage("http://www.camchickens.com/webcam.jpg");
  feeds[13] = loadImage("http://www.terrapin-gardens.net/images/webcam.jpg");
  feeds[14] = loadImage("http://stream.fisheyeview.com/FVCam.jpg");
  feeds[15] = loadImage("http://www.cs.ualberta.ca/~lake/cam/jpg/large/201.jpg");
  feeds[16] = loadImage("http://webcams.pancanal.com/webcam/miraflores.jpg");
  feeds[17] = loadImage("http://www.oceanvillageholidays.co.uk/webcam/ov1.jpg");
  feeds[18] = loadImage("http://brooklyn-bridge.mobotixcam.de/record/current.jpg?rand=380424");
  feeds[19] = loadImage("http://www.outercam.co.uk/ssc/camera3.jpg?1260446915311");
  feeds[20] = loadImage("http://www.xs4all.nl/~twocats/cam/Cam-A.jpg");
  feeds[21] = loadImage("http://www.sat.dundee.ac.uk/webcam/cam0.jpg");
  feeds[22] = loadImage("http://facweb.furman.edu/~rbryson/dramadept/TheatreCamPic.jpg");
  feeds[23] = loadImage("http://www.cbc.ca/bc/webcam/images/webcam.jpg");
  feeds[24] = loadImage("http://www.outercam.co.uk/ssc/camera2.jpg?1260455145216");
  feeds[25] = loadImage("http://www.jb.man.ac.uk/common/camera30sec.jpg?dummy=1260456117729");
  feeds[26] = loadImage("http://ecoast.vs.oiccam.com:443/ftp/capcom/jackalope/image.jpg?rand=14:52:10");
  feeds[27] = loadImage("http://www.outercam.co.uk/ssc/camera2.jpg?1260455145216");
  feeds[28] = loadImage("http://www.outercam.co.uk/ssc/camera2.jpg?1260455145216");
  feeds[29] = loadImage("http://www.outercam.co.uk/ssc/camera2.jpg?1260455145216");
 
  void setup(){
    frameRate(1);
    size(1280, 800);
  }
 
  void draw()

how do show these pictures now in a 6x5 grid? Huh
 
Re: 30 Webcam Feeds = Very Slow
Reply #7 - Dec 10th, 2009, 2:16pm
 
grids always suggest nested for loops

int index = 0;
for (y = 0 ; y < number_of_rows ; y++) {
 for (x = 0 ; x < number_of_columns ; x++) {
   image(feeds[index], x * width / 6, y * height / 5, width / 6, height / 5);
   index++;
 }
}

so first time through y = 0, x = 0 and index = 0 so you get
image(feeds[0], 0, 0, width / 6, height / 5);
etc

(you can do it with one for loop and use modulo arithmatic but the above is clearer)
Re: 30 Webcam Feeds = Very Slow
Reply #8 - Dec 10th, 2009, 2:26pm
 
but i would just have the feeds as an array of strings then you can do the initial load of the feeds using a loop in setup.

for (int i = 0 ; i < number_of_feeds ; i++) {
 feeds[i] = loadimage(feedUrl[i]);
}

and also use the same array to update the images later in draw().

int i = (int)random(number_of_feeds);
feeds[i]  = loadimage(feedUrl[i]);

but don't update all of them every frame or you're just going to end up writing a Denial Of Service script. and put a delay() in your draw too - no point requesting images 30 times a second (or even once a second) when the images are only changing every 30 seconds.
Re: 30 Webcam Feeds = Very Slow
Reply #9 - Dec 11th, 2009, 7:15am
 
Ok, I know understand how the array system works, but I can't seem to get it running! I've changed the array to strings, but when I run it, I get an error message "unexpected token: void". What have I done wrong?! Cry

my code:

String[] feeds = new String[30];

  feeds[0] = "http://www.adelaidecitycouncil.com/netcatapps/webcam/images/centralMkt.jpg";
  feeds[1] = "http://www.adelaidecitycouncil.com//NetcatApps/webcam/images/bellnth.jpg";
  feeds[2] = "http://www.adelaidecitycouncil.com/netcatapps/webcam/images/rundleEast.jpg";
  feeds[3] = "http://www.adelaidecitycouncil.com/netcatapps/webcam/images/sk8cam.jpg";
  feeds[4] = "http://www.adelaidecitycouncil.com//NetcatApps/webcam/images/bellsth.jpg";
  feeds[5] = "http://www.abbeyroad.com/webcam/crossing.jpg?cacheKiller=362683";
  feeds[6] = "http://server.fishycam.com/fishycam.jpg?time=1260184950863";
  feeds[7] = "http://www.cph.dk/CPHdata/webcam/CPH_spot1.jpg?1260188477647";
  feeds[8] = "http://www.adelaidecitycouncil.com/netcatapps/webcam/images/rundle.jpg";
  feeds[9] = "http://images.ibsys.com/sea/images/weather/auto/queenannecam_640x480.jpg?";
  feeds[10] = "http://www.pani.com/webcam/airport_tower.jpg?";
  feeds[11] = "http://www.cph.dk/CPHdata/webcam/CPH_spot3.jpg?1260369631305";
  feeds[12] = "http://www.camchickens.com/webcam.jpg";
  feeds[13] = "http://www.terrapin-gardens.net/images/webcam.jpg";
  feeds[14] = "http://stream.fisheyeview.com/FVCam.jpg";
  feeds[15] = "http://www.cs.ualberta.ca/~lake/cam/jpg/large/201.jpg";
  feeds[16] = "http://webcams.pancanal.com/webcam/miraflores.jpg";
  feeds[17] = "http://www.oceanvillageholidays.co.uk/webcam/ov1.jpg";
  feeds[18] = "http://brooklyn-bridge.mobotixcam.de/record/current.jpg?rand=380424";
  feeds[19] = "http://www.outercam.co.uk/ssc/camera3.jpg?1260446915311";
  feeds[20] = "http://www.xs4all.nl/~twocats/cam/Cam-A.jpg";
  feeds[21] = "http://www.sat.dundee.ac.uk/webcam/cam0.jpg";
  feeds[22] = "http://facweb.furman.edu/~rbryson/dramadept/TheatreCamPic.jpg";
  feeds[23] = "http://www.cbc.ca/bc/webcam/images/webcam.jpg";
  feeds[24] = "http://www.outercam.co.uk/ssc/camera2.jpg?1260455145216";
  feeds[25] = "http://www.jb.man.ac.uk/common/camera30sec.jpg?dummy=1260456117729";
  feeds[26] = "http://ecoast.vs.oiccam.com:443/ftp/capcom/jackalope/image.jpg?rand=14:52:10";
  feeds[27] = "http://www.outercam.co.uk/ssc/camera2.jpg?1260455145216";
  feeds[28] = "http://www.outercam.co.uk/ssc/camera2.jpg?1260455145216";
  feeds[29] = "http://www.outercam.co.uk/ssc/camera2.jpg?1260455145216";
 
void setup()

for (int i = 0 ; i < 30 ; i++) {
feeds[i] = loadimage(feeds[i]);
}
 
void draw()

int i = (int)random(30);
feeds[i]  = loadimage(feeds[i]);
delay(1000);
Re: 30 Webcam Feeds = Very Slow
Reply #10 - Dec 11th, 2009, 7:20am
 
The array feeds is for Strings only. You need another array with the images: imgFeeds.
Code:


String[] feeds = new String[30];
PImage[] imgFeeds;

void setup(){
for (int i = 0 ; i < feeds.length; i++) {
imgFeeds[i] = loadimage(feeds[i]);
}
}
Re: 30 Webcam Feeds = Very Slow
Reply #11 - Dec 11th, 2009, 7:32am
 
Do you mean this? The only thing is that it keeps coming up unexpected token: void. how do I get rid of that problem before I can begin to understand this one?

String[] feeds = new String[30];
PImage[] imgFeeds;

  feeds[0] = "http://www.adelaidecitycouncil.com/netcatapps/webcam/images/centralMkt.jpg";
  feeds[1] = "http://www.adelaidecitycouncil.com//NetcatApps/webcam/images/bellnth.jpg";
  feeds[2] = "http://www.adelaidecitycouncil.com/netcatapps/webcam/images/rundleEast.jpg";
  feeds[3] = "http://www.adelaidecitycouncil.com/netcatapps/webcam/images/sk8cam.jpg";
  feeds[4] = "http://www.adelaidecitycouncil.com//NetcatApps/webcam/images/bellsth.jpg";
  feeds[5] = "http://www.abbeyroad.com/webcam/crossing.jpg?cacheKiller=362683";
  feeds[6] = "http://server.fishycam.com/fishycam.jpg?time=1260184950863";
  feeds[7] = "http://www.cph.dk/CPHdata/webcam/CPH_spot1.jpg?1260188477647";
  feeds[8] = "http://www.adelaidecitycouncil.com/netcatapps/webcam/images/rundle.jpg";
  feeds[9] = "http://images.ibsys.com/sea/images/weather/auto/queenannecam_640x480.jpg?";
  feeds[10] = "http://www.pani.com/webcam/airport_tower.jpg?";
  feeds[11] = "http://www.cph.dk/CPHdata/webcam/CPH_spot3.jpg?1260369631305";
  feeds[12] = "http://www.camchickens.com/webcam.jpg";
  feeds[13] = "http://www.terrapin-gardens.net/images/webcam.jpg";
  feeds[14] = "http://stream.fisheyeview.com/FVCam.jpg";
  feeds[15] = "http://www.cs.ualberta.ca/~lake/cam/jpg/large/201.jpg";
  feeds[16] = "http://webcams.pancanal.com/webcam/miraflores.jpg";
  feeds[17] = "http://www.oceanvillageholidays.co.uk/webcam/ov1.jpg";
  feeds[18] = "http://brooklyn-bridge.mobotixcam.de/record/current.jpg?rand=380424";
  feeds[19] = "http://www.outercam.co.uk/ssc/camera3.jpg?1260446915311";
  feeds[20] = "http://www.xs4all.nl/~twocats/cam/Cam-A.jpg";
  feeds[21] = "http://www.sat.dundee.ac.uk/webcam/cam0.jpg";
  feeds[22] = "http://facweb.furman.edu/~rbryson/dramadept/TheatreCamPic.jpg";
  feeds[23] = "http://www.cbc.ca/bc/webcam/images/webcam.jpg";
  feeds[24] = "http://www.outercam.co.uk/ssc/camera2.jpg?1260455145216";
  feeds[25] = "http://www.jb.man.ac.uk/common/camera30sec.jpg?dummy=1260456117729";
  feeds[26] = "http://ecoast.vs.oiccam.com:443/ftp/capcom/jackalope/image.jpg?rand=14:52:10";
  feeds[27] = "http://www.outercam.co.uk/ssc/camera2.jpg?1260455145216";
  feeds[28] = "http://www.outercam.co.uk/ssc/camera2.jpg?1260455145216";
  feeds[29] = "http://www.outercam.co.uk/ssc/camera2.jpg?1260455145216";
 

 
void setup(){
 
for (int i = 0 ; i < 29 ; i++) {
feeds[i] = loadimage(feeds[i]);
}


for (int i = 0 ; i < feeds.length; i++) {
imgFeeds[i] = loadimage(feeds[i]);
}

}
 
void draw()

int i = (int)random(29);
feeds[i]  = loadimage(feeds[i]);
delay(1000);
Re: 30 Webcam Feeds = Very Slow
Reply #12 - Dec 11th, 2009, 7:36am
 
You cant add the items outside a function so but the feed[0]... part in your setup function.
Re: 30 Webcam Feeds = Very Slow
Reply #13 - Dec 11th, 2009, 7:41am
 
Ah got it! with that out of the way, the only problem I'm having now is that it is not recognising int - "unexpected token: int". I though this had already been declared in my code...

String[] feeds = new String[30];
PImage[] imgfeeds;


void setup(){
  feeds[0] = "http://www.adelaidecitycouncil.com/netcatapps/webcam/images/centralMkt.jpg

...

  feeds[29] = "http://www.outercam.co.uk/ssc/camera2.jpg?1260455145216";
 
for (int i = 0 ; i < 29 ; i++) {
feeds[i] = loadimage(feeds[i]);
}


for (int i = 0 ; i < feeds.length; i++) {
imgFeeds[i] = loadimage(feeds[i]);
}

}
 
void draw()

int i = (int)random(29);
feeds[i]  = loadimage(feeds[i]);
delay(1000);
Re: 30 Webcam Feeds = Very Slow
Reply #14 - Dec 11th, 2009, 7:55am
 
how do I get the "int" working on the code above? No idea!
Pages: 1 2