1

So I have convert the getDisplayPosition from the beta version of the Kinect SDK to the full version. Here's what I have right now

The Original

 private Point getDisplayPosition(Joint joint)
    {
        float depthX, depthY;
        nui.SkeletonEngine.SkeletonToDepthImage(joint.Position, out depthX, out depthY);
        depthX = Math.Max(0, Math.Min(depthX * 320, 320));  //convert to 320, 240 space
        depthY = Math.Max(0, Math.Min(depthY * 240, 240));  //convert to 320, 240 space
        int colorX, colorY;
        ImageViewArea iv = new ImageViewArea();
        // only ImageResolution.Resolution640x480 is supported at this point
        nui.NuiCamera.GetColorPixelCoordinatesFromDepthPixel(ImageResolution.Resolution640x480, iv, (int)depthX, (int)depthY, (short)0, out colorX, out colorY);


        // map back to skeleton.Width & skeleton.Height
        return new Point((int)(skeleton.Width * colorX / 640.0), (int)(skeleton.Height * colorY / 480));
    }


My Version

private Point getDisplayPosition(Joint joint)
    {
        float depthX, depthY;
        KinectSensor sensor = kinectSensorChooser1.Kinect;
        DepthImageFormat depth = DepthImageFormat.Resolution320x240Fps30;
        depthX = 320;
        depthY = 240;
        sensor.MapSkeletonPointToDepth(joint.Position, depth);
        depthX = Math.Max(0, Math.Min(depthX * 320, 320));
        depthY = Math.Max(0, Math.Min(depthY * 240, 240));
        int colorX, colorY;
        colorX = 320;
        colorY = 240;

        return new Point((int)(skeleton.Width * colorX / 640.0), (int)(skeleton.Height * colorY / 480));
    }

Basically I want to know if my version will do the same thing as the original, and if not, how to fix it.

Liam McInroy
  • 4,339
  • 5
  • 32
  • 53

1 Answers1

2

This is what I did and it works for me (this is very similar to yours) - I hope it helps:

My Version

private Point getDisplayPosition(DepthImageFrame depthFrame, Joint joint)
{ 
    float depthX, depthY;        
    DepthImagePoint depthPoint = kineticSensor.MapSkeletonPointToDepth(joint.Position, depthImageFormat);

    depthX = depthPoint.X;
    depthY = depthPoint.Y;

    depthX = Math.Max(0, Math.Min(depthX * 320, 320));
    depthY = Math.Max(0, Math.Min(depthY * 240, 240));

    int colorX, colorY;
    ColorImagePoint colorPoint = depthFrame.MapToColorImagePoint(depthPoint.X, depthPoint.Y, sensor.ColorStream.Format);
    colorX = colorPoint.X;
    colorY = colorPoint.Y;

    return new Point((int)(skeleton.Width * colorX / 640.0), (int)(skeleton.Height * colorY / 480));
}
Liam McInroy
  • 4,339
  • 5
  • 32
  • 53
Forer
  • 1,045
  • 1
  • 9
  • 32
  • Sorry cant give bounty via phone:P – Liam McInroy May 04 '12 at 12:42
  • Oh, but wouldn't I also need to have a `DepthImageFrame`? And would that effect anything? Also what is `depthImageFormat` and `sensor`? – Liam McInroy May 04 '12 at 12:53
  • depthImageFormat (DepthImageFormat instance) and Sensor (KineticSensor instance) are a couple variables in my code. I assign these when the window has loaded. I use depthImageFrame to make use of the built MapToColorImagePoint method. I used depthImageFormat as my thinking is this is an initialise value on the KineticSensor, so I want to use the same setting in this regard. In my code "sensor" is just an instance of KinectSensor instantiated when the window has loaded. Likewise, depthImageFormat is also a variable I assign after starting up the sensor. – Forer May 04 '12 at 15:24
  • 1
    FYI when you said `sensor.ColorStreamFormat`, I found that it is really `sensor.ColorStream.Format`, seeing as '`sensor` has no definition for `ColorStreamFormat`' – Liam McInroy May 06 '12 at 02:53
  • Haha lol no prob good thing I was messig with KinectSensor members that day – Liam McInroy May 07 '12 at 12:32