capturing feeds from multiple webcams

edited June 2014 in Library Questions

Hi I want to grab time lapse images from multiple webcams. I currently have six different ones to play with: my laptop's built-in one, a USB microscope webcam from Adafruit and four endoscope USB cameras from eBay. Ultimately I want to collect images from the four endoscopes at once but I have run into a problem: I can't see or save frames from more than two cameras at once. I get a grey (i.e. blank) screen where other images should appear. I've done some googling to try and work out why this is and there seem to have been various causes of this over time including Windows7's habit of giving multiple devices the same name. this shouldn't affect me as I am running XP however I went through the fix to rename devices in device manager and it hasn't helped. There's also people reporting that the video library had a bug in it in various versions of Processing. I was using 2.0b3 but I upgraded to 2.2.1 and it hasn't helped.

I've tried sketches that should save multiple camera feeds and I've tried multiple instances of sketches that save single camera feeds without success. The first couple of cameras to be started run fine and any after that don't. Once I stop a sketch where the camera hasn't run I often see the following error in the console:

(java.exe:2564): GStreamer-CRITICAL **: Trying to dispose element rgb, but it is in PAUSED instead of the NULL state. You need to explicitly set elements to the NULL state before dropping the final reference, to allow them to clean up. This problem may also be caused by a refcounting bug in the application or some element.

(java.exe:2564): GStreamer-CRITICAL **: Trying to dispose element Video Capture, but it is in PAUSED instead of the NULL state. You need to explicitly set elements to the NULL state before dropping the final reference, to allow them to clean up. This problem may also be caused by a refcounting bug in the application or some element.

Here's my example sketch:

import processing.video.*;

float fps = 2;
Boolean saveFrames = false; // set to false if you don't want the frames saved to file
String fileName = "IMG_";  // a text string that will start the file names of each saved image
String fileType = ".jpg"; // you can  choose "tif", "tga", "jpg", "png" Files.
String filePath0 = "E:\\Chris's stuff\\datalogs\\saveFrames\\cam0\\";
String filePath1 = "E:\\Chris's stuff\\datalogs\\saveFrames\\cam1\\";
String filePath2 = "E:\\Chris's stuff\\datalogs\\saveFrames\\cam2\\";
String Time;


Capture cam0;
Capture cam1;
Capture cam2;

void setup() {
  size(640,480);
  frameRate(fps);

  String[] cameras = Capture.list();

  for (int i = 0; i < cameras.length; i++) {
    print("camera " + i + ": ");
    println(cameras[i]);
  }

  // The camera can be initialized directly using an 
  // element from the array returned by list():

try {
  cam0 = new Capture(this, cameras[1]);
  cam0.start();

  cam1 = new Capture(this, cameras[11]);
  cam1.start();

  cam2 = new Capture(this, cameras[21]);
  cam2.start();
}

catch (Exception e) {
  println("Error attaching camera(s): " + e.getMessage());
  exit();
}

}      

void draw() {

cam0.read(); 
set(0, 0, cam0);
setTimestamp();
if(saveFrames) { saveFrame( filePath0 + fileName + "_cam0_" + Time + "_F##" + fileType ); }

cam1.read(); 
set(321, 0, cam1);
setTimestamp();
if(saveFrames) { saveFrame( filePath0 + fileName + "_cam1_" + Time + "_F##" + fileType ); }

cam2.read(); 
set(0, 241, cam2);
if(saveFrames) { saveFrame( filePath2 + fileName + "_cam2_" + Time + "_F##" + fileType ); }

}


// read actually date & time, create Variable
void setTimestamp() {
  String Year, Month, Day, Hour, Minute, Second;
  Year = nf( year(), 4 );
  Month = nf( month(), 2 );
  Day = nf( day(), 2 );
  Hour = nf( hour(), 2 );
  Minute = nf( minute(), 2 );
  Second = nf( second(), 2 ); 
  Time = Year + Month + Day + "_T" + Hour + Minute + Second;
}

Can anyone suggest what's going wrong?

Answers

  • Answer ✓

    Just to report the solution to my own problem: the issue appears to be one of bandwidth. The cameras were connected to my laptop through three USB 2.0 ports on a docking station and one USB3.0 port on the side of the laptop. The one on the side and one of the ones on the back would work simultaneously but not multiple cameras through the docking station. I've successfully captured from all four cameras now by plugging all four cameras directly in to a desktop PC. If I use a hub of any kind they fail. This is not a power issue, I think, because each camera has a ring of white LEDs around the lens whose brightness is controlled by a rotary dial on the USB plug. These all work fine and I imagine they draw more power than the camera itself. Regards, Chris

Sign In or Register to comment.