0

I was watching video for "Intro to Developing for Azure Kinect - BRK1001". https://www.youtube.com/watch?v=HzeYb00eQRI At the time was writing code and noticed that property Buffer is not available on Microsoft.Azure.Sensor.Image but is being referenced on the presentation. How can I use Buffer in my code?

I've installed SDK 1.2.0-alpha.10 Microsoft video is from 7th May 2019, so it's not that old.

1) Capture from video: enter image description here

2) Capture from my VS 2017: enter image description here

ej_ja
  • 45
  • 6

2 Answers2

1

You can no longer obtain the native buffer directly. It must accessed through the managed Memory accessor at color.Memory. I'm not a user of the presentation core, but it may be possible to pass that as is to WritePixels. If not, use Memory.ToArray() to obtain a "byte[]"

Jak_Ene
  • 61
  • 1
  • 3
1

The production version of C# wrapper was just released last week. We are about to publish the sample code that will resolve your problem, but this is what you are looking for for now:

private async void Window_Loaded(object sender, RoutedEventArgs e) { int count = 0;

        while (running)
        {
            using (Image transformedDepth = new Image(ImageFormat.Depth16, colorWidth, colorHeight, colorWidth * sizeof(UInt16)))
            using (Capture capture = await Task.Run(() => { return this.kinect.GetCapture(); }))
            {
                count++;

                this.transform.DepthImageToColorCamera(capture, transformedDepth);

                this.bitmap.Lock();

                var color = capture.Color;
                var region = new Int32Rect(0, 0, color.WidthPixels, color.HeightPixels);

                unsafe
                {
                    using (var pin = color.Memory.Pin())
                    {
                        this.bitmap.WritePixels(region, (IntPtr)pin.Pointer, (int)color.Size, color.StrideBytes);
                    }

                    if (boundingBox != null)
                    {
                        int y = (boundingBox.Y + boundingBox.H / 2);
                        int x = (boundingBox.X + boundingBox.W / 2);

                        this.StatusText = "The person is:" + transformedDepth.GetPixel<ushort>(y, x) + "mm away";
                    }
                }

                this.bitmap.AddDirtyRect(region);
                this.bitmap.Unlock();

                if (count % 30 == 0)
                {
                    var stream = StreamFromBitmapSource(this.bitmap);
                    _ = computerVision.AnalyzeImageInStreamAsync(stream, MainWindow.features).ContinueWith((Task<ImageAnalysis> analysis) =>
                    {
                        try
                        {
                            foreach (var item in analysis.Result.Objects)
                            {
                                if (item.ObjectProperty == "person")
                                {
                                    this.boundingBox = item.Rectangle;
                                }
                            }
                        }
                        catch (System.Exception ex)
                        {
                            this.StatusText = ex.ToString();
                        }
                    }, TaskScheduler.FromCurrentSynchronizationContext());
                }
            }
        }
    }
Tetyana Sych
  • 101
  • 3