将 Kinect 方法从 Beta 2 转换为版本 1

本文关键字:转换 版本 Beta Kinect 方法 | 更新日期: 2023-09-27 18:32:47

所以我将getDisplayPosition从Kinect SDK的测试版转换为完整版。这是我现在
拥有的原

 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));
    }


我的版本

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));
    }

基本上,我想知道我的版本是否会与原始版本执行相同的操作,如果没有,如何修复它。

将 Kinect 方法从 Beta 2 转换为版本 1

这就是我所做的,它对我有用(这与你的非常相似) - 我希望它有所帮助:

我的版本

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));
}