简体   繁体   English

使用EMGU库处理Kinect RGB图像时,我的应用程序速度变慢

[英]My application slows down when processing Kinect RGB images with EMGU library

I'm currently using Kinect SDK with C# ( WPF application). 我目前正在将Kinect SDK与C#(WPF应用程序)结合使用。 I need to get RGB stream and process the images with EMGU library. 我需要获取RGB流并使用EMGU库处理图像。 The problem is when i try to process the image with EMGU ( like converting image's format and change the colour of some pixels ) the application slows down and takes too long to respond . 问题是当我尝试使用EMGU处理图像时(例如转换图像的格式并更改某些像素的颜色),应用程序速度变慢并且响应时间过长。 I'm using 8GO RAM / Intel HD graphics 4000 / Intel core i7 . 我正在使用8GO RAM /英特尔高清显卡4000 /英特尔酷睿i7。

Here's my simple code : http://pastebin.com/5frLRwMN 这是我的简单代码: http : //pastebin.com/5frLRwMN

Please help me :'( 请帮我 :'(

I have run considerably heavier code (blob analysis) with the Kinect on a per frame basis and got away with great performance on a machine of similar configuration as yours, so I believe we can rule out your machine as the problem. 我在每帧的基础上使用Kinect运行了相当多的代码(斑点分析),并且在与您的配置类似的机器上获得了出色的性能,因此,我相信我们可以排除您的机器是问题所在。 I don't see any EMGU code in your sample however. 但是,您的示例中没有看到任何EMGU代码。 In your example, you loop through 307k pixels with a pair of for loops. 在您的示例中,您通过一对for循环遍历307k像素。 This is naturally a costly procedure to run, depending on the code in your loops. 根据循环中的代码,这自然是一个昂贵的过程。 As you might expect, GetPixel and SetPixel are very slow methods to execute. 如您所料,GetPixel和SetPixel是执行速度非常慢的方法。

To speed up your code, first turn your image into an Emgu Image. 要加快代码速度,请首先将您的图像转换为Emgu图像。 Then to access your image, use a Byte: 然后使用字节访问图像:

Byte workImageRed = image.Data[x, y, 0];
Byte workImageGreen = image.Data[x, y, 1];
...

The third column refers to the BGR data. 第三列是BGR数据。 To set the pixel to another colour, try something like this: 要将像素设置为另一种颜色,请尝试如下操作:

byte[,,] workIm = image.Data;
workIm[x, y, 0] = 255;
workIm[x, y, 1] = 20;
...

Alternatively, you can set the pixel to a colour directly: 另外,您可以直接将像素设置为一种颜色:

image[x, y] = new Bgr(Color.Blue);

This might be slower however. 但是,这可能会更慢。

Image processing is always slow. 图像处理总是很慢。 And if you do it at 30fps, it's normal that you get you app to hang: real time image processing is always a challenge. 而且,如果您以30fps的速度运行,则挂起应用程序是正常的:实时图像处理始终是一个挑战。 You may need to drop some frames in order to increase performace (...or perhaps switch to native C++ and seek a faster library). 您可能需要丢弃一些帧以提高性能(...或者也许切换到本机C ++并寻求更快的库)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM