ofxKinect average depth of 1 blob - help me, running out of time

hi folks, i’m on a very short deadline for my bachelor project and i need your help with this.

i want to track one person via ofxkinect and 2 kinects, it’s very simple, both kinects should just give me the depth information of one single blob so i can map them to an x and y position. The kinects are positioned in a right angle.

Right now i just ask for the center of the blobs, but the values aren’t very smooth. Can you help me to get an smooth average distance of one blob?

right now i work with something like this

contourFinder.findContours(grayImage, 100, (kinect.width*kinect.height)/2, 1, false);  
		if (contourFinder.nBlobs>0){  

i would be very grateful if someone could give me a hand with this, thx nixon

i would make a vector of a ofVec3f and a function to:

  • check for a vector size, if its more than x delete last element
  • insert the ofVec3f in the vector

in update check for blob, if blob found push_back the centroid in the vector
when you want to use the value, you want to sum all values in the z position and divide that by the vector length
this way you have an average ofVec3f point

hope that helps

Can you post some example. The object I want to trigger is a ofvec3f vector where I pass the distance as x and y positions

hm, i dont know ofxKinect, but ofxOpenNI can give you directly a 3dVector of a tracked User (the center of the tracked user), i would try to get the MEDIAN of this over the last seconds from both cams…
greetings ascorbin

Mh, I m afraid its to late to change to openni… But I think ofxkinect can achive that kind of things

You should just sum the depth over the contour. I don’t have a Kinect to test this with, but something like:

for( int i = 0; i < contourWidth; i++) {  
    for( int j = 0; j < contourHeight; j++) {  
        sum += getDistanceAt(i, j);  
sum /= contourWidth*contourHeight;  

You probably just want to get a region around the centroid, say like 16x16 pixel area.

1 Like

Hey, thx for the reply, how can I get acces for the centeroid pixels? I get some values now but they arent very constant if somebody stands

contourFinder.findContours(grayImage, 40, (kinect.width*kinect.height)/2, 1, false);  
		if (contourFinder.nBlobs>0){  
			for(int i=0;i<contourFinder.getWidth();i++){  
				for(int j =0;j<contourFinder.getHeight();j++){  
					sum += kinect.getDistanceAt(i,j);  
			sum /= contourFinder.getWidth()*contourFinder.getHeight();  

this is the code i wrote, perhaps you see something that is important to change

contourFinder is the component that finds the countours. What I would do is get the contour x and y position and then look at the pixels contained within that.

for( int i = contourFinder.blobs[0].centroid.x - 8; i < contourFinder.blobs[0].centroid.x + 8; i++) {  
    for( int j = contourFinder.blobs[0].centroid.y - 8; j < contourFinder.blobs[0].centroid.y + 8; j++) {  
        dist += kinect.getDistanceAt(i,j);    
dist /= 64; // i.e. 8x8  

hey, thx again for the provided code. the project worked out pretty well :slight_smile: