【问题标题】:Image Processing with Kinect and AForge使用 Kinect 和 AForge 进行图像处理
【发布时间】:2013-04-06 13:25:23
【问题描述】:

我正在开展一个项目,我想使用 AForge.NET-Library 使用 Microsoft Kinect 跟踪骰子。 该项目本身仅包含初始化 Kinect、获取 Colorframe 和应用一个滤色器等基础知识,但问题已经出现。 所以这里是程序的主要部分:

void ColorFrameReady(object sender, ColorImageFrameReadyEventArgs e)
    {
        using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
        {
            if (colorFrame != null)
            {
                colorFrameManager.Update(colorFrame);
                BitmapSource thresholdedImage =
                    diceDetector.GetThresholdedImage(colorFrameManager.Bitmap);

                if (thresholdedImage != null)
                {
                    Display.Source = thresholdedImage;
                }
            }

        }
    }

“colorFrameManager”对象的“更新”方法如下所示:

public void Update(ColorImageFrame colorFrame)
    {
        byte[] colorData = new byte[colorFrame.PixelDataLength];
        colorFrame.CopyPixelDataTo(colorData);

        if (Bitmap == null)
        {
            Bitmap = new WriteableBitmap(colorFrame.Width, colorFrame.Height,
                96, 96, PixelFormats.Bgr32, null);
        }
        int stride = Bitmap.PixelWidth * Bitmap.Format.BitsPerPixel / 8;
        imageRect.X = 0;
        imageRect.Y = 0;
        imageRect.Width = colorFrame.Width;
        imageRect.Height = colorFrame.Height;
        Bitmap.WritePixels(imageRect, colorData, stride, 0);
    }

“getThresholdedImage”方法如下所示:

public BitmapSource GetThresholdedImage(WriteableBitmap colorImage)
    {
        BitmapSource thresholdedImage = null;
        if (colorImage != null)
        {
            try
            {
                Bitmap bitmap = BitmapConverter.ToBitmap(colorImage);
                HSLFiltering filter = new HSLFiltering();
                filter.Hue = new IntRange(335, 0);
                filter.Saturation = new Range(0.6f, 1.0f);
                filter.Luminance = new Range(0.1f, 1.0f);
                filter.ApplyInPlace(bitmap);
                thresholdedImage = BitmapConverter.ToBitmapSource(bitmap);
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message);
            }
        }
        return thresholdedImage;
    }

现在程序变慢了很多/执行此行时没有响应:

filter.ApplyInPlace(bitmap);

所以我已经阅读了这个线程 (C# image processing on Kinect video using AForge),我尝试了 EMGU,但由于内部异常,我无法让它工作,而且线程启动器自四个月以来就没有在线,我的问题是看看在他的工作代码没有得到回答。 现在首先我对执行缓慢的原因很感兴趣

filter.ApplyInPlace(bitmap);

这种图像处理真的那么复杂吗?或者这可能是我的环境问题? 其次我想问一下跳帧是否是一个好的解决方案?或者最好每隔 - 例如 - 500毫秒使用轮询和打开帧。 非常感谢!

【问题讨论】:

    标签: image-processing kinect aforge


    【解决方案1】:

    HSL 过滤器不会减慢计算速度,它不是一个复杂的过滤器。 我在 30 fps 的 320x240 图像中使用它没有问题。

    问题可能在于计算图像的分辨率或帧速率过高!

    如果图像的分辨率很高,我建议在任何过滤器应用之前调整它的大小。 而且我认为 20 帧速率(可能更少)足以跟踪骰子。

    【讨论】:

    • 感谢您的回答。图像的分辨率为 640 * 480,帧率通常为每秒 30 帧。目前,当我请求/仅使用 Kinect 的每三帧时,我每秒处理大约 10 帧。但是我担心如果我做更多的图像处理(我必须做些什么来检测骰子和数字),帧率会大大降低。但尽管如此,我还是会尝试先调整图像大小,看看帧率是否发生变化。
    • 如果你也在追号,又怕320*240的分辨率不够,可以稍微调整一下。当你得到框架时,你复制它并将大小调整为一半(320 * 240)。调整大小的副本将用于跟踪 RED 骰子(更快),因此您可以毫无问题地应用 HSL 过滤器。当 RED 骰子位于帧中时,您转换其坐标(即: X * 2 ),您将在原始图像中使用该坐标来获取数字。但我建议您在简单调整大小之前尝试一下。我觉得320x240的分辨率就够了!
    • 谢谢,这似乎工作得很好,因为我可以跟踪骰子;帧率通常在每秒 8 到 10 帧之间,但对于这个项目来说已经足够了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-13
    相关资源
    最近更新 更多