Filtering Capture.list()

Im printing out contents of a capture.list(), and ive managed to only print cameras with 10 fps like this:

String[] cameras = Capture.list();

String fps = "fps=10";

// String size = "size";

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

{

String cam = cameras[i];

String[] camSplit = split(cam, ',');

if(fps.equals(camSplit[2]) == true) {

 print("camera " + i + ": ");

 println(cameras[i]);

}

And this is the output:

camera 3: name=webcam2,size=1280x720,fps=10

camera 22: name=webcam2,size=1280x800,fps=10

camera 50: name=HP Truevision HD,size=1280x720,fps=10

There are: 57

is there a way to make it forget the others? so it would print out camera 1, 2 and 3 instead of 3, 22, 50?

any feedback would be grateful.

Tagged:

Answers

  • Just for loop over it and if fps ok copy in a new array

  • edited April 2018

    it doesnt seem to like it, it throws a ArrayIndexOutOfBoundsException

  • show your code

  • do i've avoided the error, but im not too sure what im doing. code is here:

    void setup() {

    size (640, 320);

    String[] cameras = Capture.list();

    String fps = "fps=30";

    String[] cameras1 = {""};

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

    String cam = cameras[i];

    String[] camSplit = split(cam, ',');

    if(fps.equals(camSplit[2]) == true){

     arrayCopy(cameras, cameras1, 1);
    
     print("camera " + i + ": ");
    
     println(cameras1);
    

    }

    }

    if i remove the 1 from arrayCopy() the error appears, cameras1 is the new array.

  • An array is a fixed size, you can't add more elements to it, just change the existing (0) element.

    Try an ArrayList.

Sign In or Register to comment.