Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 1.18 KB  |  hits: 38  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Kinect raw depth to distance in meters
  2. if (depthValue < 2047)
  3. {
  4.   depthM = 1.0 / (depthValue*-0.0030711016 + 3.3309495161);
  5. }
  6.        
  7. using (var skeletonFrame= e.OpenSkeletonFrame())
  8. using (var depthFrame = e.OpenDepthImageFrame())
  9. {
  10.     skeletonFrame.CopySkeletonDataTo(skeletons);
  11.     var skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength];
  12.  
  13.     foreach (var skeleton in skeletons)
  14.     {
  15.             if (skeleton.TrackingState != SkeletonTrackingState.Tracked) continue;
  16.  
  17.             var head = skeleton.Joints[JointType.Head];
  18.             if (head.TrackingState == JointTrackingState.NotTracked) continue;
  19.  
  20.             var depthImagePoint = depthFrame.MapFromSkeletonPoint(head.Position);
  21.  
  22.             int depthInMillimeters = depthImagePoint.Depth; // TADA!
  23.     }
  24. }
  25.        
  26. using (var depthFrame = e.OpenDepthImageFrame())
  27. {
  28.     var depthArray = new short[depthFrame.PixelDataLength];
  29.     depthFrame.CopyPixelDataTo(depthArray);
  30.  
  31.     for (int i = 0; i < depthArray.Length; i++) {
  32.         int depthInMillimeters =
  33.             depthArray[i] >> DepthImageFrame.PlayerIndexBitmaskWidth;
  34.         // TADAx2!
  35. }
  36.        
  37. if (depthValue <= 2047) {
  38.    depthM = 0.1236 * Math.Tan(depthValue / 2842.5 + 1.1863);
  39. }