Having trouble with some code

edited December 2016 in Kinect

So, I am working on a program using the xbox kinect, i keep getting an error saying that my avgY doesnt exist (towards the bottom of the code in the if statement.) Any help? I am following Shiffmans videos on how to make a color tracking BTW

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();
}

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

 float Record = 500;

 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){
      Record = d;
      avgX += x;
      avgY += y;
      count++;

     }
   }
   }



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

 fill(trackColor);
 srokeWeight(3.0);
 stroke(0);
 ellipse(avgX, avgY, 16, 16);
}
}
Tagged:

Answers

Sign In or Register to comment.