We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
SOUND AND TRACKING COLOR FROM WEBCAM (Read 1062 times)
SOUND AND TRACKING COLOR FROM WEBCAM
Jan 12th, 2010, 9:37am
 
I would like track lights  in the dark from a webcam and create sounds.
Firstly I am trying to create for one light,sound changing with the position of the light.
I would like keep the  lights for a size given
Next create for multiple lights
Please help me Shocked


import processing.video.*;
Capture myCapture;

color trackColor;
import ddf.minim.*;
import ddf.minim.signals.*;
Minim minim;
AudioOutput out;
SineWave sine;
void setup() {
 size(320, 240);
 
 minim = new Minim(this);
 // get a line out from Minim, default bufferSize is 1024, default sample rate is 44100, bit depth is 16
 out = minim.getLineOut(Minim.STEREO);
 // create a sine wave Oscillator, set to 440 Hz, at 0.5 amplitude, sample rate from line out
 sine = new SineWave(440, 0.5, out.sampleRate());
 // set the portamento speed on the oscillator to 200 milliseconds
 sine.portamento(200);
 // add the oscillator to the line out
 out.addSignal(sine);
 myCapture = new Capture(this, width, height,30);
 
 noFill();
smooth();
strokeWeight(4.0);
stroke(0);


}

void captureEvent(Capture myCapture) {
 myCapture.read();
 
}

void draw() {
 
 loadPixels();
 image(myCapture, 0, 0);

 filter(INVERT);
 filter(THRESHOLD,0.2);
 filter(INVERT);
 float closestDiff = 500.0f;
   int closestX =0;
   int closestY =0;
 for(int x = 0; x<myCapture.width;x++){
 for (int y=0;y<myCapture.height;y++){
      int loc = x + y*myCapture.width;
    color currentColor = myCapture.pixels[loc];
 float r1 = red(currentColor); float g1 = green(currentColor); float b1 = blue(currentColor);
    float r2 = red(trackColor); float g2 = green(trackColor);   float b2 = blue(trackColor);
float d = dist(r1,g1,b1,r2,g2,b2);
   if(  (d < closestDiff)){
     closestDiff = d;
     closestX =x;
     closestY =y;
   println("En X ="+x+" et Y = "+y+ "le pixel est blanc" );
   float freq = map(closestX, 0, height, 1500, 60);
   
sine.setFreq(freq);
 float Pan=1-(closestY/float(width))*2;

 }
loc++;

   }
   }
   }
Page Index Toggle Pages: 1