Idk what is wrong (color tracking)

edited December 2016 in Kinect

So I am making a color tracking program using the kinect, I am following daniel shiffmans videos. For some reason the program isnt working the way I want tit too. I see the video that the kinect is picking up but I cant do what Shiffman does in his videos where he clicks a color and it follows. Any tips? I think it is because i am using the kinect library and a video library.

import org.openkinect.freenect.*;
import org.openkinect.freenect2.*;
import org.openkinect.processing.*;
import org.openkinect.tests.*;

import processing.video.*;

Kinect kinect;
Capture video;

color trackColor;

float threshold = 25;

void setup() {
  size(640, 520);
  kinect = new Kinect(this);
  video = new Capture(this, width, height); 
  kinect.initVideo();
  trackColor = color(255,0,0);
}

void draw(){
  background(0);
  image(kinect.getVideoImage(), 0, 0);


 int avgX = 0;
 int avgY = 0;

 int count = 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 = blue(currentColor);
     float b1 = green(currentColor);
     float r2 = red(trackColor);
     float g2 = blue(trackColor);
     float b2 = green(trackColor);

     float d = dist(r1,b1,g1,r2,b2,g2);

     if (d < threshold){

      avgX += x;
      avgY += y;
      count++;

     }
   }
   }



if (count > 0){
 avgX = avgX / count;
 avgY = avgY / count;

 fill(trackColor);
 strokeWeight(3.0);
 stroke(0);
 ellipse(avgX, avgY, 16, 16);
}
}

void mousePressed(){
 int loc = mouseX + mouseY*video.width;
 trackColor = video.pixels[loc];
}

Answers

Sign In or Register to comment.