Measuring 3D Distances between points using Kinect

Now time to move on to some simple application from the kinect depth image.

As I mentioned , Kinect keep track of depth values of all the pixels related to pixel position.

 That points are corresponding to the real world instances of points. So every point on this depth image 

can be considered as three dimensional vector as (X, Y, V) as below.

X Value,

Y Value,

Z Value, 

from the Cartesian coordinate system. We can demonstrate the point as 3 Dimensional vector 

shown below,

So if we denote two instant of point as Vector, We can easily calculate distances between them.



 C = V1U1


Then we can get magnitude of the C, that’s mean the distance between Point1 and Point2. Before 

Explaining the How I code , I will show the Code and Result,




 Result has pretty good accuracy as I expected.

To implement a vector, we can use PVector Data type form the processing with tree argument x1, y1

 and z1.
                                      
PVector vector1 = new PVector(x1, y1, depth1);

Also PVector library has sub() and mag() method to  subtract to vectors and get magnitude of a
vectors 

Now I will summarize the  detail. If you find it difficult to understand any of above code feel free
to ask. 


  • First, setup () part is same as before it allow access to Depth value by enableDepth () method. And 

  • code convert mirror image come from the Data to actual image by .setmirror (true) method

  • Also it initialize two array as X and Y, to hold the X and Y positions of two points.
# Code uses two Boolean flags to identify whether two points are set or not.


  • In draw(), checks whether flogs are set or not ,
If only one flag is sat, it  draws a little red circle on the selected point
If both  flags are sat, then it will draw circle on both points and draw a line in between them.


  • Then cal_distance () is called. It will return the distance between two point using vector method as explained and print it bottom of the screen.

  • Additionally I added additional line to reduce the high variance of the distance value displayed  ,
    value += value +0.1* (diff-value);   
                                                                                                                            
Which actually reduces the high oscillation of the final value

you can choose the constant value (0.1) appropriately


Comments

Popular posts from this blog

Implementation - Robot Navigation

Full stack development of Robot navigation