Willkommen auf unserem Seminar-Blog

Immer auf dem aktuellen Stand bleiben

Dieser Seminar-Blog befindet sich noch im Aufbau und wird in den kommenden Tagen entsprechend verfeinert.

Member Login

Lost your password?

Registration is closed

Sorry, you are not allowed to register by yourself on this site!

You must either be invited by one of our team member or request an invitation by email at viad.info {at} zhdk {dot} ch.

Tracking Color

März 5, 2012

import processing.video.Capture;
Capture video;

int threshold = 20; 
int aveX, aveY; 
float objectR =255;
float objectG = 0;
float objectB = 0;
boolean debug = true;
int lastTime; 
void setup() {
  size(640, 480);
  println(Capture.list());
  video = new Capture(this,width,height);

}
void draw(){
  if (video.available()){
 
    lastTime = millis();  
    video.read();
    int totalFoundPixels= 0;  
    int sumX = 0;  
    int sumY = 0;

  for (int row = 0; row < video.height; row++) {
      for (int col = 0; col < video.width; col++) {

        int offset = row * width + col;
   
        int thisColor = video.pixels[offset];

        float r = red(thisColor);
        float g = green(thisColor);
        float b = blue(thisColor);

        float diff = dist(r, g, b, objectR, objectG, objectB);

        if (diff < threshold) { 
          sumX = sumX + col;
          sumY= sumY + row;
          totalFoundPixels++;
          if (debug) video.pixels[offset] = 0xff000000;
        }
      }
    }
    if (debug) image(video,0,0);
    if (totalFoundPixels > 0){
      aveX = sumX/totalFoundPixels;
      aveY = sumY/totalFoundPixels;
      ellipse(aveX-10,(aveY-10),20,20);
    }
  }
}
void mousePressed(){

  int offset = mouseY * width + mouseX;
  int thisColor = video.pixels[offset];


   objectR = red(thisColor);
   objectG = green(thisColor);
   objectB = blue(thisColor);

}