How can I use multiple webcams?

edited July 2017 in Library Questions

i want to use the integrated camera from the netbook and two external webcams. how can I get the index number form the cameras?

Tagged:

Answers

  • Check more towards the end but most of the post is informative:

    https://forum.processing.org/two/discussion/comment/78656/#Comment_78656

    Kf

  • thanks! but still doesent work with 3 webcams

  • Make sure you can access each cam individually before trying all three at the same time. Then Try two at the time. Also please post the code you have so far. Show your approach.

    Kf

  • edited July 2017
        //colores a elegir
        color color1 = color(0, 255, 0);
        color color2 = color(255, 0, 0);
        color fondo = color(0, 0, 0);
        //thresholds de brillo
        float treshold2;
        float treshold1;
        //cuentafotos
        int suma = 0;
        int bandera = 0;
        //importa la biblioteca de video
        import processing.video.*;
    
        Capture cam1;
        Capture cam2;
        //Capture cam3;para agregar mas camaras
    
        void setup() {
          size(640, 480);
    
          String[] cameras = Capture.list();
          //if de seguridad
          if (cameras.length == 0) {
            println("There are no cameras available for capture.");
            exit();
          } else {
            println("Available cameras:");
          }
          for (int i = 0; i < cameras.length; i++) {
            println(cameras[i]);
          }
    
          cam1 = new Capture(this, cameras[0]);
          cam2 = new Capture(this, cameras[12]);
          //metodo para comenzar las camaras
          cam1.start();
          cam2.start();
          //carga de pixeles
          loadPixels();
          cam1.loadPixels();
          cam2.loadPixels();
        }
    
        //el trehold de la cam2 se controlacon el mouse dragged
        void mouseDragged() {
          treshold2 = map(mouseX, 0, width, 0, 255);
          treshold1 = map(mouseY, 0, width, 0, 255);
        }
    
    
        void draw() {
          if (cam1.available() == true) {
            cam1.read();
          }
    
          if (cam2.available() == true) {
            cam2.read();
          }
    
          //println(cam1.width,cam1.height);
          //recorrer los pixeles de las camaras
          for (int y = 0; y<cam2.width; y++)
          {
            for (int x = 0; x<cam1.height; x++)
            {      
              //buscapixeles
              int loc = x+y*cam1.height;
              //banderas de brillo
              int loc1 = 0;
              int loc2 = 0;
              //medidores de brillo para cada camara
              float bright1 = brightness(cam1.pixels[loc]);
              float bright2 = brightness(cam2.pixels[loc]);
    
              if (bright1>treshold1)
              {
                loc1 = 1;
              }
    
              if (bright2>treshold2)
              {
                loc2 = 1;
              }
    
              if (loc1 == 1 && loc2 == 0)
              {
                pixels[loc] = color1;
              }
    
              if (`loc2==1 && loc1==0)
              {
                pixels[loc] = color2;
              }
    
              if (loc1 == 1 && loc2==1) {
                pixels[loc] = color1+color2;
              }
    
              if (loc1 == 0 && loc2==0) {
                pixels[loc] = fondo;
              }
            }
          }
          updatePixels();
        }
    
        void mousePressed() {
          for (int i = 0; i<suma; i++) {
            saveFrame("data/pruebas"+i+".jpg");
          }
          suma++;
        }
    

    this is the code, its a video sinthetizer trying to bea replica of the paik-abe sinthethizer

  • Please describe the problem you are having currently. Do you get an error? You get nothing? Also try implementing the algorithm as described in the link from earlier post as they were tested. Before try to work with brightness calculations, just focus in displaying the images in the canvas. Remove code that is not needed for this part of the troubleshooting. Can we assume the cameras work if run one by one by themselves?

    Kf

  • There's an obvious error in line 90

  • Lines 62 and 64 are confusing. And 67.

    Outer loop should be y and height, inner loop should be x and width. Index is x + (y * width). Yours might be equivalent but the above is clearer.

    Line 108 is nonsense. You don't need a loop.

  • treshold1 = map(mouseY, 0, width, 0, 255);

    why are you mapping mouseY with width?

    for (int y = 0; y<cam2.width; y++) { for (int x = 0; x<cam1.height; x++)

    cam2.width but cam1.height? you will have no end of problems if the cameras are different sizes.

Sign In or Register to comment.