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.
IndexProgramming Questions & HelpVideo Capture,  Movie Playback,  Vision Libraries › controlling oscillator with video camera feed
Page Index Toggle Pages: 1
controlling oscillator with video camera feed (Read 651 times)
controlling oscillator with video camera feed
Jun 21st, 2009, 4:05pm
 
I modified the BackgroundSubtraction video example that came with Processing to control an oscillator - essentially, the faster i move in front of the camera, the higher pitch the note is. Unfortunately, this is very choppy and not easily accurate for playing specific notes. My question is, how can I take this code and draw "zones" in which movement could be differentiated and thus cause seperate operations to execute? (essentially turning the video capture into a virtual touchscreen). I dont think this should be too difficult, I just have little experience with the video coding side of Processing.

Thanks,

J.

The code:

import processing.video.*;

import ddf.minim.*;
import ddf.minim.signals.*;
PFont font;
Minim minim;
AudioOutput out;
PulseWave sine;

int numPixels;
int[] previousFrame;
Capture video;

void setup() {
 font = loadFont("Baskerville-SemiBoldItalic-48.vlw");
 size(320, 240, P2D);
 video = new Capture(this, width, height, 24);
 numPixels = video.width*video.height;
 previousFrame = new int[numPixels];
 loadPixels();


 minim = new Minim(this);

 out = minim.getLineOut(Minim.STEREO);

 sine = new PulseWave(0, .6, out.sampleRate());

 sine.portamento(50);

 out.addSignal(sine);
}

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

   video.read();
   video.loadPixels();
   int movementSum = 0;
   for (int i = 0; i < numPixels; i++) {
     color currColor = video.pixels[i];
     color prevColor = previousFrame[i];

     int currR = (currColor >> 16) & 0xFF;
     int currG = (currColor >> 8) & 0xFF;
     int currB = currColor & 0xFF;

     int prevR = (prevColor >> 16) & 0xFF;
     int prevG = (prevColor >> 8) & 0xFF;
     int prevB = prevColor & 0xFF;

     int diffR = abs(currR - prevR);
     int diffG = abs(currG - prevG);
     int diffB = abs(currB - prevB);

     movementSum += diffR + diffG + diffB;



     pixels[i] = 0xff000000 | (diffR << 16) | (diffG << 8) | diffB;

     previousFrame[i] = currColor;
   }


   println(movementSum);

   if ((movementSum > 700000) && (movementSum < 1000000)) {

     sine.setFreq(700.81);




   }
   if ((movementSum > 1000001) && (movementSum < 1200000)) {


     sine.setFreq(900.63);
   }

   if ((movementSum > 1200001) && (movementSum < 1400000)){


     sine.setFreq(1000.25);
   }

   if ((movementSum > 1400001)&&(movementSum < 1600000)){

     sine.setFreq(1200.50);
   }

   if ((movementSum > 1600001)&&(movementSum < 1800000)){

     sine.setFreq(1290.50);
   }

   if ((movementSum > 1800001)&&(movementSum < 2000000)){

     sine.setFreq(1400.50);
   }

   if ((movementSum > 2000001)&&(movementSum < 2600000)){

     sine.setFreq(1504.50);
   }
   if (movementSum > 2600001){

     sine.setFreq(1600.50);
   }
 }



}





void stop()
{
 out.close();
 minim.stop();

 super.stop();
}
Re: controlling oscillator with video camera feed
Reply #1 - Jun 23rd, 2009, 7:28am
 
you simply need to make multiple for cycles: instead of cycling throught the whole frame like you're doing now, you'll have to cycle into your different areas and set different behaviors for each of them.
Page Index Toggle Pages: 1