Tracking nearest object

I think you guys now familiar with Kinect depth image and how it’s behave. Next I will explain some basic structure that will help you to do some basic programming with Kinect.

Before that, If not go to my first blog post from here.



As I mention before Kinect keep track of depth values of  all most all the pixels related to pixel position which are corresponding to the real world instances.

If we can access to that depth value pixels using an array ,using simple algorithm we can track which pixel have least depth, then our goal is completed. Actually SimpleOpenNI have pretty match all the necessary data arrangement to achieve this task very  easily.

This method of keep tracking nearest or specific place which have specific characteristic like width range ,height range, depth range or a RGB value rang can be adapted to many application like robotic, Automation and etc.

Now I will explain to you how I achieved it.                                                                                             Before that  this is the Processing Code and of cause results




At the time observation taken, Nearest point was my little figure in left hand. You can verify your code working correctly by the tracked point which should have in brightest portion in side the gray scale depth image.

Now I will summarize the code work with the specific detail. If you find any difficulty to understand any of above code feel free to answer.

  • First, setup() part is same as before it allow access to Depth value by  enableDepth() method.
  • In draw(), first interesting thing is at the beginning it initiate it nearest value as far value  so that it can operate smoothly at the beginning
  • Then it access depth value array (which is a 1 D array representing all the pixel values considering as one line)   by depthMap() method.
  • Next part is accessing this array using nested two for loop,representing X and Y coordinate initiating left upper corner of depth image  as  (0,0) point.
  • Basically in this nested loop compare every depth value in the depthMap array with the current closest value ,if comparing value is smaller than the current closest it will set as current closest and it’s  coordinate as closest point X and Y coordinate.
  • At the end of the nested loops , program has the closest point corresponded to the current depth value data set.
  • Finally , Program draws a ellipse around that current closest point using it coordinate Values.





Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s