Capture.list() function finds wrong number of cameras

My goal is to have processing connecting to every webcam connected to the pc,but even with two cameras the code:

Capture cam;
String[] cameras = Capture.list();

for (int i = 0; i < cameras.length; i++) {

(from the manual,edited to add spacing) outputs something like this:

name=Logitech HD Webcam C270,size=640x480,fps=5
name=Logitech HD Webcam C270,size=640x480,fps=30
name=Logitech HD Webcam C270,size=160x120,fps=5
name=Logitech HD Webcam C270,size=352x288,fps=5
name=Logitech HD Webcam C270,size=352x288,fps=30
name=Logitech HD Webcam C270,size=1280x720,fps=5
name=Logitech HD Webcam C270,size=1280x720,fps=30
name=Logitech HD Webcam C270,size=1280x960,fps=5
name=Logitech HD Webcam C270,size=1280x960,fps=30
name=Logitech QuickCam Pro 9000,size=320x240,fps=5
name=Logitech QuickCam Pro 9000,size=320x240,fps=30
name=Logitech QuickCam Pro 9000,size=352x288,fps=5
name=Logitech QuickCam Pro 9000,size=352x288,fps=30
name=Logitech QuickCam Pro 9000,size=640x360,fps=5

actually there are more than 80 lines for each camera...

So I guess that processing lists every possible combination of resolution and fps... How do I connect only to the "real" webcams? I could try to identify them by the name but What if there are 2 same model cameras?

And anyway is there a way to detect when a camera is connected to the pc after the program has started?

Thanks to everybody.... waiting for you



  • edited July 2015 Answer ✓

    Just conjecturing, since I've never had more than 1 webcam in the same computer:

    • For 2 cameras, you're gonna need 2 Capture instances.
    • And they're gonna share the same captureEvent() callback!
    • In order to identify how many cameras there are and their best resolution + FPS, you're gonna need to write some very smart parser.
    • From the String[] returned by Capture.list(), split() it by ',' in order to get those 3 properties: name, size & fps.
    • Then split() again each of them by '=' in order to separate those properties from their respective values.
    • Finally the parser gonna have the necessary data in order to pick the best setup for each Capture.

    But what if there are 2 same model cameras?

    Dunno. Perhaps we'd see identical String or w/ some slightly diff. name? :-/

  • edited July 2015

    awww man I accidentally pressed yes but I'm not completely satisfied; Anyway, your is a good idea but the problem is also that since Capture.list() has over 150 elements calling this function,wich is needed to have cameras working ,becomes very slow; with just 2 cameras and calling only:


    it takes up to 20 sec to start the program;and with 3 it takes over 40 secs! So does every computer load such weird list of camera combinations or is it some setting I have?

  • edited September 2015

    This function returns an array with the unique values of the camera names:

        import java.util.HashSet;
        import java.util.Arrays;
        void setup()
          // Get list of camera names
          String[] camNames = getCameraNames();
          for (int i = 0; i < camNames.length; i++)
        void draw()
        String[] getCameraNames()
          String[] list = Capture.list();
          for (int i=0; i < list.length; i++)
            String[] chunks = split(list[i], ',');
            chunks = split(chunks[0], '=');
            list[i] = chunks[1];
          String[] unique = new HashSet<String>(Arrays.asList(list)).toArray(new String[0]);
          return unique;
Sign In or Register to comment.