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);
                                }
                            }
                        }
                }
            }
        }
예제 #2
0
        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()); }))
                // Get Capture Image and Transformed Image
                #if TO_COLOR
                    using (K4A.Image color_image = capture.Color)
                        using (K4A.Image depth_image = transformation.DepthImageToColorCamera(capture))
                #else
                    using (K4A.Image color_image = transformation.ColorImageToDepthCamera(capture))
                        using (K4A.Image depth_image = capture.Depth)
                #endif
                        {
                            // Get Color Buffer and Write Bitmap
                            byte[] color_buffer = color_image.Memory.ToArray();
                            color_bitmap.WritePixels(color_rect, color_buffer, color_stride, 0, 0);

                            // Get Depth Buffer, and Write Bitmap
                            ushort[] depth_buffer = depth_image.GetPixels <ushort>().ToArray();
                            depth_bitmap.WritePixels(depth_rect, Array.ConvertAll(depth_buffer, i => (byte)(i * (255.0 / 5000.0))), depth_stride, 0, 0);
                        }
            }
        }
예제 #3
0
        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()); }))
                {
                    // Enqueue Tracker
                    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);

                            // Transform Body Index Map to Color Camera
                            (K4A.Image _, K4A.Image body_index_map)reult =
                                transformation.DepthImageToColorCameraCustom(
                                    frame.Capture.Depth,
                                    frame.BodyIndexMap,
                                    K4A.TransformationInterpolationType.Nearest,
                                    K4ABT.Frame.BodyIndexMapBackground
                                    );

                            //Get Body Index Map Buffer
                            byte[] body_index_map_buffer = reult.body_index_map.Memory.ToArray();

                            // Draw Body Index Map and Write Bitmap
                            Parallel.For(0, body_index_map_buffer.Length, i =>
                            {
                                uint index = (uint)body_index_map_buffer[i];
                                if (index != K4ABT.Frame.BodyIndexMapBackground)
                                {
                                    Color color = colors[index % colors.Length];
                                    colorized_body_index_map_buffer[i * 4 + 0] = color.B;
                                    colorized_body_index_map_buffer[i * 4 + 1] = color.G;
                                    colorized_body_index_map_buffer[i * 4 + 2] = color.R;
                                    colorized_body_index_map_buffer[i * 4 + 3] = color.A;
                                }
                                else
                                {
                                    colorized_body_index_map_buffer[i * 4 + 0] = 0;
                                    colorized_body_index_map_buffer[i * 4 + 1] = 0;
                                    colorized_body_index_map_buffer[i * 4 + 2] = 0;
                                    colorized_body_index_map_buffer[i * 4 + 3] = 255;
                                }
                            });
                            body_index_map_bitmap.WritePixels(body_index_map_rect, colorized_body_index_map_buffer, body_index_map_stride, 0, 0);

                            // Clear Body Index Map
                            reult.body_index_map.Dispose();
                        }
                }
            }
        }
예제 #4
0
 private Image GetImage(Microsoft.Azure.Kinect.Sensor.Capture capture)
 {
     return(this.ImageType switch
     {
         KinectCaptureImage.Depth => capture.Depth,
         KinectCaptureImage.IR => capture.IR,
         _ => capture.Color,
     });
예제 #5
0
 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()); }))
             // Get Capture Image
             using (K4A.Image depth_image = capture.Depth)
             {
                 // Get Depth Buffer, and Write Bitmap
                 ushort[] depth_buffer = depth_image.GetPixels <ushort>().ToArray();
                 depth_bitmap.WritePixels(depth_rect, Array.ConvertAll(depth_buffer, i => (byte)(i * (255.0 / 5000.0))), depth_stride, 0, 0);
             }
     }
 }
예제 #6
0
 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()); }))
             // Get Capture Image
             using (K4A.Image color_image = 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);
             }
     }
 }
예제 #7
0
 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()); }))
             // Get Capture Image
             using (K4A.Image infrared_image = capture.IR)
             {
                 // Get Infrared Buffer, and Write Bitmap
                 ushort[] infrared_buffer = infrared_image.GetPixels <ushort>().ToArray();
                 infrared_bitmap.WritePixels(infrared_rect, Array.ConvertAll(infrared_buffer, i => (byte)(i * 0.5)), infrared_stride, 0, 0);
             }
     }
 }
예제 #8
0
        private void OnCaptureArrived(object sender, Microsoft.Azure.Kinect.Sensor.Capture capture)
        {
            var handler = this.frameArrived;

            if (handler != null)
            {
                using var image = this.GetImage(capture)?.Reference();
                handler         = this.frameArrived;
                if (image != null && handler != null)
                {
                    var frame    = new DecodedKinectCaptureFrame(image.Reference(), this);
                    var oldFrame = Interlocked.Exchange(ref this.lastFrame, frame);
                    oldFrame?.Dispose();

                    handler = this.frameArrived;
                    handler?.Invoke(this, EventArgs.Empty);
                }
            }
        }