首页 > 解决方案 > Azure Kinect 传感器 SDK - 用于图像捕获的 C# 包装器缺少“缓冲区”?

问题描述

我正在观看“Azure Kinect 开发简介 - BRK1001”的视频。 https://www.youtube.com/watch?v=HzeYb00eQRI 当时正在编写代码并注意到该属性在演示文稿Buffer中不可用Microsoft.Azure.Sensor.Image但正在被引用。如何Buffer在我的代码中使用?

我已经安装了 SDK 1.2.0-alpha.10 Microsoft 视频来自 2019 年 5 月 7 日,所以它不是那么旧。

1)从视频中捕获: 在此处输入图像描述

2)从我的 VS 2017 中捕获: 在此处输入图像描述

标签: c#kinectkinect-sdkazurekinect

解决方案


C# wrapper的生产版本于上周刚刚发布。我们即将发布可以解决您的问题的示例代码,但这是您现在正在寻找的:

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

推荐阅读