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.

05 Color Tracking mit Bild

Februar 24, 2012


import processing.video.*;


Capture video;
PShape [] s;
int index = 0;

color trackColor;

void setup() {
size(640,480);

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

trackColor = color(200,200,0);

s = new PShape[3];
s[0] = loadShape("biene.svg");
s[1] = loadShape("auge.svg");
s[2] = loadShape("kaefer.svg");
shapeMode(CENTER);
smooth();
}

void draw() {
if (video.available()) {
video.read();
}
video.loadPixels();
image(video,0,0);

float worldRecord = 500;

int closestX = 0;
int closestY = 0;

for (int x = 0; x < video.width; x ++ ) {
for (int y = 0; y < video.height; y ++ ) {
int loc = x + y*video.width;

color currentColor = video.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 < worldRecord) {
worldRecord = d;
closestX = x;
closestY = y;
}
}
}

if (worldRecord < 10) {
smooth();
shape(s[index], closestX, closestY, 70, 70);

}
}

void mousePressed()
{

int loc = mouseX + mouseY*video.width;
trackColor = video.pixels[loc];
}

void keyPressed()
{
if(keyPressed == true)
{
index++;
}

if(index == s.length)
{
index = 0;
}
}