Get pixeldata of capture image in P3D

Hey ho everybody!

i have trouble in getting colorinformations from an captured webcam image. its no problem to use the camera picture as an texture for some vertexes... but i want to analyse the dynamical colorchange of each pixel the camera tracks.

thats exatly what i want to do... just using P3D:

    import processing.video.*;
    final int VIDEO_WIDTH  = 320;
    final int VIDEO_HEIGHT = 240;
    // Anzahl der Quadranten in der Breite
    final int VIDEO_COLS   = 8;
    // Anzahl der Quadranten in der Höhe
    final int VIDEO_ROWS   = 6;
    float[] activity = new float[VIDEO_COLS * VIDEO_ROWS];
    float[] buffer1 = new float[VIDEO_WIDTH * VIDEO_HEIGHT];
    float[] buffer2 = new float[buffer1.length];
    float[] buffer3 = new float[buffer1.length];
    Capture cam = null;

    void setup () {
      size (VIDEO_WIDTH, VIDEO_HEIGHT);
      cam = new Capture (this, VIDEO_WIDTH, VIDEO_HEIGHT, 15);
      frameRate (15);
    }

    void draw () {

      if (cam.available ()) {

        cam.read ();

        int index;
        int pxPerCol = VIDEO_WIDTH / VIDEO_COLS;
        int pxPerRow = VIDEO_HEIGHT / VIDEO_ROWS;

        image (cam, 0, 0);

        // 'activity' array auf 0 setzen
        for (int i=0; i < activity.length; i++) {
          activity[i] = 0;
        }

        // Für jedes Pixel im Videoraster
        for (int i=0; i < cam.pixels.length; i++) {

          // x und y Position des Quadranten berechnen
          int x = (int) ((i % cam.width) / pxPerCol);
          int y = (int) ((i / cam.width) / pxPerRow);

          // Quadranten-Zugehörigkeit des Pixels herausfinden.
          // Später wichtig für das 'activity' array.
          index = y * VIDEO_COLS + x;

          // Farbe an der Position 'i' im Kamerabild
          color col = cam.pixels[i];
          // Die Summe aus allen drei Farbkanälen bilden
          float sum = red (col) + green (col) + blue (col);

          // Farbwertänderung des Pixels bezogen auf alle Bilder errechnen
          float deltaPixel = (buffer1[i] + buffer2[i] + buffer3[i]) / 3 - sum;

          if (deltaPixel < 0) {
            deltaPixel *= -1;
          }

          // Die Änderung auf den Gesamtwert des Quadranten addieren
          activity[index] += deltaPixel;

          // Verschiebe das 'Bildgedächnis' um einen Rutsch nach hinten.
          buffer3[i] = buffer2[i];
          buffer2[i] = buffer1[i];
          buffer1[i] = sum;
        }

        // Für jeden Quadranten
        for (int i=0; i < activity.length; i++) {

          // Durchschnittliche Farbwertänderung berechnen.
          // Mit dem Teilen der Summe durch die Anzahl der Pixel
          activity[i] /= pxPerCol* pxPerRow;

          // Quadrant in das Sketchfenster zeichnen
          stroke (255, 20);
          fill (0, 255, 230, activity[i]);
          rect ((i % VIDEO_COLS) * pxPerCol, (i / VIDEO_COLS) * pxPerRow, pxPerCol, pxPerRow);
        }
      }
    }

i dont know how to get the cam.pixels[] in any way...

im looking forward to any possible solution! thx

Tagged:

Answers

  • I can't fully understand you code, but if you are looking to get pixels information from the camera image do it as you would with any other PImage, use get()

Sign In or Register to comment.