C#Kinect绘图点在履带式手上

时间:2015-03-17 01:25:32

标签: c# kinect

我有以下代码:

if (frame != null)
                {
                    canvas.Children.Clear();
                    _bodies = new Body[frame.BodyFrameSource.BodyCount];

                    frame.GetAndRefreshBodyData(_bodies);

                    foreach (var body in _bodies)
                    { 
                        if (body != null)
                        {
                            if (body.IsTracked)
                            {
                                // choose which hand to track
                                string whichHand = "right"; //change to "left" in order to track left hand
                                Joint handRight = body.Joints[JointType.HandRight];


                                if (whichHand.Equals("right"))
                                {

                                    string rightHandState = "-"; //find the right hand state

                                    switch (body.HandRightState)
                                    {
                                        case HandState.Open:
                                            rightHandState = "Open";
                                            break;
                                        case HandState.Closed:
                                            rightHandState = "Closed";
                                            break;
                                        default:
                                            break;
                                    }
                                    canvas.DrawPoint(handRight, _sensor.CoordinateMapper);
                                }

这是我的DrawPoint代码:

public static void DrawPoint(this Canvas canvas, Joint joint, CoordinateMapper mapper)
{
    if (joint.TrackingState == TrackingState.NotTracked) return;

    Point point = joint.Scale(mapper);

    Ellipse ellipse = new Ellipse
    {
        Width = 20,
        Height = 20,
        Fill = new SolidColorBrush(Colors.LightBlue)
    };

    Canvas.SetLeft(ellipse, point.X - ellipse.Width / 2);
    Canvas.SetTop(ellipse, point.Y - ellipse.Height / 2);

    canvas.Children.Add(ellipse);
}

和比例:

public static Point Scale(this Joint joint, CoordinateMapper mapper)
{
    Point point = new Point();

    ColorSpacePoint colorPoint = mapper.MapCameraPointToColorSpace(joint.Position);
    point.X *= float.IsInfinity(colorPoint.X) ? 0.0 : colorPoint.X;
    point.Y *= float.IsInfinity(colorPoint.Y) ? 0.0 : colorPoint.Y;

    return point;
}

我遇到的问题是,当圆圈被绘制时,它不会被我的手绘制。相反它停留在左上角(0,0),因此我猜测它没有得到正确的更新。谁能告诉我发生了什么事或问题是什么?我希望它在我的手中心(由于手的状态立即更新而被跟踪得很好)并在我移动时跟随我的手。

_sensor是我的Kinect传感器。

0 个答案:

没有答案