How to get the screen coordinates of a joint or more per screen?

0

Very good, I've been trying for a couple of weeks to get the coordinates for example of HandLeft (left hand) that I visualize with Kinect inside my WPF application in Visual Studio, but I can not think of how to do it.

The part of the code where I think the code should go to show on the screen:

foreach (Body body in this.bodies)
{
    Pen drawPen = this.bodyColors[penIndex++];

    if (body.IsTracked)
    {
        this.DrawClippedEdges(body, dc);

        IReadOnlyDictionary<JointType, Joint> joints = body.Joints;
        // Console.WriteLine("HandRight" + JointType.HandRight);

        // convert the joint points to depth (display) space
        Dictionary<JointType, Point> jointPoints = new Dictionary<JointType, Point>();

        // Text = ms_distance_x.ToString("#.##");

        foreach (JointType jointType in joints.Keys)
        {
            // sometimes the depth(Z) of an inferred joint may show as negative
            // clamp down to 0.1f to prevent coordinatemapper from returning (-Infinity, -Infinity)
            CameraSpacePoint position = joints[jointType].Position;
            if (position.Z < 0)
            {
                position.Z = InferredZPositionClamp;
            }

            DepthSpacePoint depthSpacePoint = this.coordinateMapper.MapCameraPointToDepthSpace(position);
            jointPoints[jointType] = new Point(depthSpacePoint.X, depthSpacePoint.Y);
        }

        this.DrawBody(joints, jointPoints, dc, drawPen);

        this.DrawHand(body.HandLeftState, jointPoints[JointType.HandLeft], dc);
        this.DrawHand(body.HandRightState, jointPoints[JointType.HandRight], dc);
    
asked by Daniel Potrimba 16.05.2017 в 11:51
source

2 answers

0
this.sensor.DepthFrameReady += this.Sensor_DepthFrameReady;
this.interaction = new InteractionStream(sensor, new InteractionClient());
this.interaction.InteractionFrameReady += interaction_InteractionFrameReady;

...

private void Sensor_DepthFrameReady(object sender, DepthImageFrameReadyEventArgs e)
{
    using (var frame = e.OpenDepthImageFrame())
    {
        if (frame != null)
        {
            try
            {
                interaction.ProcessDepth(frame.GetRawPixelData(), frame.Timestamp);
            }
            catch (InvalidOperationException) { }
        }
    }
}

private void interaction_InteractionFrameReady(object sender, InteractionFrameReadyEventArgs e)
{
    using (var frame = e.OpenInteractionFrame())
    {
        if (frame != null)
        {
            if ((interactionData == null) || 
                (interactionData.Length !== InteractionStream.FrameUserInfoArrayLength))
            {
                interactionData = new UserInfo[InteractionStream.FrameUserInfoArrayLength];
            }
            frame.CopyInteractionDataTo(interactionData);

            foreach (var ui in interactionData)
            {
                foreach (var hp in ui.HandPointers)
                {
                    // Get screen coordinates
                    var screenX = hp.X * DisplayWidth;
                    var screenY = hp.Y * DisplayHeight;

                    // You can also access IsGripped, IsPressed etc.
                }
            }
        }
    }
}

Since I do not control much of C # I do not know if it can help you, I hope so, if you do not let me know

    
answered by 16.05.2017 / 12:30
source
1

Well, the way I've managed to do, from my point of view, simplifies the code a lot and I think it's a good solution, the only problem is that you have to implement a TextBlock in the interface for each coordinates X Y Z of joint that you are interested in, putting a specific name to each one and then identify them and make a call to those blocks. The part of global variables is a part of code of my application, that part is not necessary to take out on screen. Whereupon the part of the code would be this:

txtHandLeftX.Text = VariablesGlobales.HandLeftX.ToString("HandLeftX : 0.0000");
                            txtHandLeftY.Text = VariablesGlobales.HandLeftY.ToString("HandLeftY : 0.0000");
                            txtHandLeftZ.Text = VariablesGlobales.HandLeftZ.ToString("HandLeftZ : 0.0000");
    
answered by 18.05.2017 в 10:49