Go Down

Topic: help processing (Read 316 times) previous topic - next topic

morrigan

Nov 23, 2009, 07:07 pm Last Edit: Nov 23, 2009, 09:50 pm by morrigan Reason: 1
good morning,

i have to realize an interactive vertical projection with the shapes of people walking in the space, and i have to add at shapes a different number.
The cam-video has a stop-image of 7 sec every 5 sec (so it will be likea stop-motion effect).
I never worked in Processing before but i tried to do a couple of patches. I don't know if they will be usefull.
I need about the multitracking.. I saw OpenCV on internet but i'm not able to create the libraries. I tried to do this but it was not possible and i don't know why...(i've a Mac). I'm thinking to start from the multiblob code to make the shapes.
i wish about some help please......the deadline is the 3th of january.

thank u so much!!!



//number+tracking+framerate(1)//


PFont fontA;
float radius = 50.0;
int X, Y;
int nX, nY;
int delay = 16;

int num = 60;
float mx[] = new float[num];
float my[] = new float[num];

import processing.video.*;

Capture video;



void setup() {

 size(640, 480); // Change size to 320 x 240 if too slow at 640 x 480

 video = new Capture(this, width, height, 30);

 smooth();

 fontA = loadFont("Courier-48.vlw");
  textFont(fontA, 30);
  strokeWeight( 10 );
 frameRate( 15 );
 X = width / 2;
 Y = width / 2;
 nX = X;
 nY = Y;

video.frameRate(1);
}

void draw() {
 if (video.available()) {
   video.read();
 
 

 
   image(video, 0, 0, width, height); // Draw the webcam video onto the screen
   int brightestX = 0; // X-coordinate of the brightest video pixel
   int brightestY = 0; // Y-coordinate of the brightest video pixel
   int fontAX = 0;
   int fontAY = 0;
   float brightestValue = 250; // Brightness of the brightest video pixel
 
   video.loadPixels();
   int index = 0;
   for (int y = 0; y < video.height; y++) {
     for (int x = 0; x < video.width; x++) {
     
       int pixelValue = video.pixels[index];
     
       float pixelBrightness = brightness(pixelValue);
     
             if (pixelBrightness > brightestValue) {
         brightestValue = pixelBrightness;
         brightestY = y;
         brightestX = x;
         nX = x;
         nY = y;
          for(int i=1; i<num; i++) {
   mx[i-1] = mx;
   my[i-1] = my;

 }

  mx[num-1] = x;
 my[num-1] = y;



 for(int i=0; i<num; i++) {
   ellipse(mx, my, i/0.8, i/0.8);
   //text( Y, X, radius, radius );
 }

       }
       index++;
     }
   }
    radius = radius + sin( frameCount / 4 );
     X+=(nX-X)/delay;
 Y+=(nY-Y)/delay;
  stroke(255);
  text( Y, X, radius, radius );
     }
}


----------------


//silhouette//


import processing.video.*;
Capture video;


class Form {
   int[][] v = new int[0][3];
   int y;
   color c;
   Form(int x,int y) {
       this.y = y;
       addRow(x,y);
       this.c = lerpColor(#ff0000,#0000ff,1);  
   }
 
   void addRow(int x, int y) {
       int[] v_n = new int[3];
       v_n[0] = x;
       v_n[1] = x;
       v_n[2] = y;
       v = (int[][]) append(v, v_n);
   }
 
   void draw(int nr) {
       line(v[0][0],v[0][2],v[0][1],v[0][2]);
       for (int i=0;i<v.length-1;i++){
           stroke(c,35);
           strokeWeight(4);
           line(v
  • ,v[2],v[i+1][0],v[i+1][2]);
               line(v[1],v[2],v[i+1][1],v[i+1][2]);
           }
           line(v[v.length-1][0],v[v.length-1][2],v[v.length-1][1],v[v.length-1][2]);
       }
     
       String toString() {
           String a = "------------START---------\n";
           for (int i=0;i<v.length-1;i++){
               a+="["+v
    • +"|"+v[1]+"|"+v[2]+"]\n";
             }
             a +="------------END-----------\n";
             return a;
         }
      }


      Form[] f =  new Form[0];

      void setup() {
       size(640, 480);
       video = new Capture(this, width, height, 10);
       noStroke();
       smooth();
       ellipseMode(CENTER);
      }

      void draw() {
         //background(255);
         if (video.available()) {
             f = new Form[0];
             video.read();
             image(video, 0, 0, width, height);
             video.loadPixels();
             int index = 0;
             int raster = 4;
             for (int y = 0; y < video.height; y+=raster) {
               for (int x = 0; x < video.width; x+=raster) {
                 int pixelValue = video.pixels[y*video.width+x];
                 boolean intresting = brightness(pixelValue)<80;
                 if (intresting) {
                     boolean old_spot = false;
                     for (int i=0; i<f.length && !old_spot ; i++){
                         Form fi = f;
                         int row = fi.v.length-1;
                         int dx = x-fi.v[row][1];
                         int dy = y-fi.v[row][2];
                         if (dx<=2*raster && dy<=2*raster) {
                             old_spot = true;
                             if (fi.v[row][2]<y) {
                                 fi.addRow(x,y);
                             }
                             else {
                                 fi.v[row][1] = x;
                             }
                         }
                     }
                     if (!old_spot) {
                         Form new_form = new Form(x,y);
                         f = (Form[]) append(f,new_form);
                     }
                 }
               }
             }
           
         }
         for (int i=0; i<f.length; i++) {
             f.draw(i);
         }
      }

      void keyPressed() {
         for (int i=0; i<f.length; i++) {
             print(f);
         }
      }

Grumpy_Mike

You might get better luck asking this on a Processing site http://processing.org/ as this one is dedicated to using an arduino.

Also please post code between the brackets that pop up when you hit the hash icon in the reply box.

Go Up