2011年2月1日 星期二

processing program

two point detection succeed
can adjust the sensitivity even work in a room light condition


import processing.video.*;
import ddf.minim.*;
AudioPlayer player;
AudioPlayer player2;
Minim minim;
Minim minim2;
Capture video;
void setup()
{
  size(1024, 400);
  minim = new Minim(this);
  minim2 = new Minim(this);
  player = minim.loadFile("try2.mp3", 2048);
  player2 = minim2.loadFile("kick.mp3", 2048);
 // player2 = minim2.loadFile("kick.mp3", 1024);
 
 
  // The name of the capture device is dependent those
  // plugged into the computer. To get a list of the
  // choices, uncomment the following line
  // println(Capture.list());
  // And to specify the camera, replace "Camera Name"
  // in the next line with one from Capture.list()
  // myCapture = new Capture(this, width, height, "Camera Name", 30);
 
  // This code will try to use the last device used
  // by a QuickTime program
 video = new Capture(this, width, height, 24);
//player.loop();
}
void draw() {
 // video.read(); //must
  image(video, 0, 0);  //must

  if (video.available()) {
    boolean p = (false);
    boolean p2 = (false);
    video.read();
    video.loadPixels();//make it can calculate
   
    int point1=video.get(64,63);
    int point2=video.get(128,63);
   
    float point1bright= brightness(point1);
    float point2bright= brightness(point2);
   
    point(64,64);
    point(127,64);
   
if (point1bright<230){
  println("dark") ;
//        player.play();
//        player.loop();
//        p=(true);
        //player.pause();
 
      } 
       //if (p==false) end
if ( player.isPlaying())  {}
else{
 if (point1bright>230){
  println("bright") ;
  player.loop();
   player.play();  }
    }
   
   
   
   
if (point2bright<230){
  println("dark2") ;
//        player.play();
//        player.loop();
//        p=(true);
        //player.pause();
 
      } 
       //if (p==false) end
if ( player2.isPlaying())  {}
else{
 if (point2bright>230){
  println("bright2") ;
  player2.loop();
   player2.play();  }
    }



}//available end
}//draw end

沒有留言:

張貼留言