我一直在使用新的Azure Kinect DK制作一系列教程,我偶然发现了一些让我感到困惑的东西。
这是一个带有MvvM模式的WPF应用程序,可以从Kinect获取输出,并且有一个组合框,允许用户从各种选项中选择输出类型。
我正在使用的最新选择是使用azure自定义视觉AI进行品牌识别。我已经训练了一个带有多个品牌软饮料的简单模型,它正确地检测到了品牌,并给出了一个边界框,其中引用了位置的原始图像的%。
我使用以下代码将彩色相机的输出作为Span中的像素:
<BGRA> colourBuffer = capture.Color.GetPixels<BGRA>().Span;
Span<BGRA> outputBuffer = outputImage.GetPixels<BGRA>().Span;我的目标是对彩色相机输出的像素进行着色,我已经成功地完成了身体跟踪:Successfully shading pictures
我已经从自定义视觉AI中获得了我的品牌预测,它是以原始图像的百分比表示的边界框。我将这些转换成Int32Rects,以便更容易地使用彩色相机输出的宽高比(1920x1080)。
我的问题是,当我着色像素时,跨度与我着色的像素不对应。完整的代码在这里:https://github.com/craiggilchrist/mancavecoding-kinectdk/blob/feature/tutorial-3/src/Part%201%20-%20Connecting/KinectViewModel.cs,但特别重要的部分是:
foreach (var prediction in _predictions)
{
// Pixels to colour will start at the top left pixel and finish after the width plus height has been iterated.
var bbX = (int)Math.Round(prediction.BoundingBox.Left * _colourWidth);
var bbX2 = bbX + ((int)Math.Round(prediction.BoundingBox.Width * _colourWidth));
var bbY = (int)Math.Round(prediction.BoundingBox.Top * _colourHeight);
var bbY2 = bbY + ((int)Math.Round(prediction.BoundingBox.Height * _colourHeight));
var region = new Int32Rect(
(int)(capture.Color.WidthPixels * prediction.BoundingBox.Left),
(int)(capture.Color.HeightPixels * prediction.BoundingBox.Top),
(int)(capture.Color.WidthPixels * prediction.BoundingBox.Width),
(int)(capture.Color.HeightPixels * prediction.BoundingBox.Height));
for (int x = region.X; x < region.X + region.Width; x++)
{
for (int y = region.Y; y < region.Y + region.Height; y++)
{
outputBuffer[(x * y)].R = 255;
}
}
}这会导致以下像素被着色为红色:Badly shaded pixels
我不知道如何正确地跨过连续的记忆,并将其绑定回我需要着色的矩形。
有人能帮上忙吗?
发布于 2020-07-15 04:08:09
事实证明,我只是在我的for循环上犯了一个愚蠢的错误。正确的for循环应该是:
for (int y = region.Y; y < region.Y + region.Height; y++)
{
for (int x = region.X; x < region.X + region.Width; x++)
{
var index = (y * _colourWidth) + x;
outputBuffer[index].R = 255;
}
}https://stackoverflow.com/questions/62885398
复制相似问题