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