private async void Window_Loaded(object sender, RoutedEventArgs e)
        {
            while (true)
            {
                // Get Capture Frame
                using (K4A.Capture capture = await Task.Run(() => { return(this.device.GetCapture()); }))
                {
                    // Enque Capture
                    tracker.EnqueueCapture(capture);

                    // Pop Result
                    using (K4ABT.Frame frame = tracker.PopResult())
                        // Get Color Image
                        using (K4A.Image color_image = frame.Capture.Color)
                        {
                            // Get Color Buffer and Write Bitmap
                            byte[] color_buffer = color_image.Memory.ToArray();
                            color_bitmap.WritePixels(color_rect, color_buffer, color_stride, 0, 0);

                            // Clear All Ellipse from Canvas
                            Canvas_Body.Children.Clear();

                            // Draw Skeleton
                            for (uint body_index = 0; body_index < frame.NumberOfBodies; body_index++)
                            {
                                // Get Skeleton and ID
                                K4ABT.Skeleton skeleton = frame.GetBodySkeleton(body_index);
                                uint           id       = frame.GetBodyId(body_index);

                                // Draw Joints
                                for (int joint_index = 0; joint_index < (int)K4ABT.JointId.Count; joint_index++)
                                {
                                    // Get Joint and Position
                                    K4ABT.Joint joint    = skeleton.GetJoint(joint_index);
                                    Vector2?    position = calibration.TransformTo2D(joint.Position, K4A.CalibrationDeviceType.Depth, K4A.CalibrationDeviceType.Color);

                                    if (!position.HasValue)
                                    {
                                        continue;
                                    }

                                    // Create Ellipse
                                    const int       radius       = 10;
                                    SolidColorBrush stroke_color = new SolidColorBrush(colors[id % colors.Length]);
                                    SolidColorBrush fill_color   = new SolidColorBrush((joint.ConfidenceLevel >= K4ABT.JointConfidenceLevel.Medium) ? colors[id % colors.Length] : Colors.Transparent);
                                    Ellipse         ellipse      = new Ellipse()
                                    {
                                        Width = radius, Height = radius, StrokeThickness = 1, Stroke = stroke_color, Fill = fill_color
                                    };

                                    // Add Ellipse to Canvas
                                    Canvas.SetLeft(ellipse, position.Value.X - (radius / 2));
                                    Canvas.SetTop(ellipse, position.Value.Y - (radius / 2));
                                    Canvas_Body.Children.Add(ellipse);
                                }
                            }
                        }
                }
            }
        }
    public UJoint(Joint joint)
    {
        Vector3 kinectSpacePosition = joint.Position.ToUnityVector3();

        Position   = AdjustScale(kinectSpacePosition);
        Rotation   = joint.Quaternion.ToUnityQuaternion();
        Confidence = joint.ConfidenceLevel;
    }
    /// <summary>
    /// Get all joints with their original position and rotation
    /// </summary>
    /// <returns></returns>
    public UJoint[] ResolveSkeleton()
    {
        //Debug.Log("Resolving Skeleton");
        //get all joint positions
        UJoint[] joints = new UJoint[27];

        for (int i = 0; i < 27; i++)
        {
            Joint  j          = trackedBody.GetJoint(i);
            UJoint unityJoint = new UJoint(j);
            joints[i] = unityJoint;
        }

        if (AppManager.recording)
        {
            MotionManager.Instance.StoreFrame(joints);
        }

        return(joints);
    }
Пример #4
0
        // Converts Azure Kinect SDK BT Body to PoseDataJSON (serializable for JSON) pose
        public static PoseDataJSON Body2PoseDataJSON(Body body)
        {
            JointDataJSON[] joint_data_array = new JointDataJSON[(int)JointId.Count];
            for (JointId jt = 0; jt < JointId.Count; jt++)
            {
                // write recorded poses to file
                Microsoft.Azure.Kinect.BodyTracking.Joint joint = body.Skeleton.GetJoint(jt);
                var pos         = joint.Position;
                var orientation = joint.Quaternion;
                // save raw data
                var v          = new Vector3(pos.X, pos.Y, pos.Z);
                var r          = new Quaternion(orientation.X, orientation.Y, orientation.Z, orientation.W);
                var joint_data = new JointDataJSON {
                    position = JsonUtility.ToJson(v), rotation = JsonUtility.ToJson(r)
                };
                joint_data_array[(int)jt] = joint_data;
            }
            PoseDataJSON jdl = new PoseDataJSON {
                data = joint_data_array
            };

            return(jdl);
        }
Пример #5
0
        // Converts Azure Kinect SDK BT Body to PoseData pose
        public static PoseData Body2PoseData(Body body)
        {
            JointData[] joint_data_live_array = new JointData[(int)JointId.Count];
            PoseData    live_data             = new PoseData {
                data = { }
            };

            for (JointId jt = 0; jt < JointId.Count; jt++)
            {
                Microsoft.Azure.Kinect.BodyTracking.Joint stickJoint = body.Skeleton.GetJoint(jt);
                var       stickPos         = stickJoint.Position;
                var       stickOrientation = stickJoint.Quaternion;
                JointData joint_data_live  = new JointData
                {
                    Position    = new Vector3(stickPos.X, stickPos.Y, stickPos.Z),
                    Orientation = new Quaternion(stickOrientation.X, stickOrientation.Y, stickOrientation.Z, stickOrientation.W)
                };
                joint_data_live_array[(int)jt] = joint_data_live;
            }
            live_data = new PoseData {
                data = joint_data_live_array
            };
            return(live_data);
        }
Пример #6
0
 public static void Assign(this LineRenderer lR, int index, Joint joint) =>
 lR.SetPosition(index, -joint.Position.ToUnityVector3() / 200f);