We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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
which video?
code looks ok, the same as his.
try printing out
count
, line 58, see what kind of values you are getting.I am not an expert in kinetic, but I notice you have a capture device and the kinetic device. From what I see in your code, you draw your kinetic image but you are processing the capture image (from the video object). If kinetic and the capture devices are not related at all, I would suggest you change line 25 with
image(video, 0, 0);
and then next to this line addvideo.loadPixels();
.For your mousePressed() function, it will be changed to this:
You also need to add in your first line of draw():
I am looking at this as a reference: https://github.com/shiffman/LearningProcessing/blob/master/chp16_video/example_16_11_ColorTrack/example_16_11_ColorTrack.pde
Kf
thanks guys I wil try this out!
Whilst you're there, move lines 41-43 outside the double loop - you don't need to recalculate them every pixel, they won't change.
continued here (ffs)
https://forum.processing.org/two/discussion/19737/really-confused-on-how-to-go-about-this