Kinect - closest point tracking in 3D
              in 
             Integration and Hardware 
              •  
              6 months ago    
            
 
           
             Hi,
            
             
            
            
             
            
            
             
            
            
             
            
            
             
            
            
              
           
 
            
           
             I try to draw lines in 3D by tracking closest point.
            
            
             Here is a code which works in 2D. 
            
            
            
             I would like to write a 3D version of this.
            
            
             However, I could not achieve it in 3D. I added closestZ, lastZ, interpolatedZ values to this sketch, but it doesn't work. Where is the problem?
            
            - import processing.dxf.*;
 - import SimpleOpenNI.*;
 - SimpleOpenNI kinect;
 - int closestValue;
 - int closestX;
 - int closestY;
 - int closestZ;
 - float lastX;
 - float lastY;
 - float lastZ;
 - void setup()
 - {
 - size(640, 480, P3D);
 - kinect = new SimpleOpenNI(this);
 - kinect.enableDepth();
 - // start out with a black background
 - background(0);
 - beginRaw(DXF, "output.dxf");
 - }
 - void draw()
 - {
 - closestValue = 8000;
 - kinect.update();
 - int[] depthValues = kinect.depthMap();
 - for (int y = 0; y < 480; y++) {
 - for (int x = 0; x < 640; x++) {
 - // reverse x by moving in from
 - // the right side of the image
 - int reversedX = 640-x-1;
 - // use reversedX to calculate
 - // the array index
 - int i = reversedX + y * 640;
 - int currentDepthValue = depthValues[i];
 - // only look for the closestValue within a range
 - // 610 (or 2 feet) is the minimum
 - // 1525 (or 5 feet) is the maximum
 - if (currentDepthValue > 610 && currentDepthValue < 1525
 - && currentDepthValue < closestValue) {
 - closestValue = currentDepthValue;
 - closestZ = currentDepthValue;
 - closestX = x;
 - closestY = y;
 - }
 - }
 - }
 - // "linear interpolation", i.e.
 - // smooth transition between last point
 - // and new closest point
 - float interpolatedX = lerp(lastX, closestX, 0.3f);
 - float interpolatedY = lerp(lastY, closestY, 0.3f);
 - float interpolatedZ = lerp(lastZ, closestZ, 0.3f);
 - stroke(255, 0, 0);
 - // make a thicker line, which looks nicer
 - strokeWeight(3);
 - line(lastX, lastY, lastZ, interpolatedX, interpolatedY, interpolatedZ);
 - lastX = interpolatedX;
 - lastY = interpolatedY;
 - lastZ = interpolatedZ;
 - }
 - void keyPressed() {
 - if (key == 'r'|| key == 'R') {
 - endRaw();
 - exit();
 - }
 - }
 
 
              
              1  
            
 
            