2011-06-28 28 views
0

我有几个站出来,在目前一个网站,他们只是报道说,其中一个显示以下错误:打开CV GUI错误处理器 - 内存不足

打开CV GUI错误处理程序

不足内存(内存不足)的功能cvAlloc ,.cvalloc.cpp(111)

这些机器做的很少,他们连接到的Suprema RealScan生物手指扫描器:http://www.supremainc.com/eng/product/ls_20.php?mark=52

我怀疑问题来自以下内容:

作为此设备SDK的一部分,您可以注册“预览回调”。这意味着当设备启动时,此回调会触发并提供指向图像的指针,该图像是来自扫描仪的实际图像。这用于使您可以显示用户手指放置在设备上时的实时图像。 callBack在设备处于捕获模式时每隔几毫秒触发一次。当设备停止捕获callBacks时停止。

当我们开始整合SDK时,我们意识到它允许我们将这个图像指针转换为C#图像类型的唯一方法是通过一个将指针数据保存到文件的函数。然后,我们必须从创建的文件中读取图像,然后删除文件。我们认为这有点疯狂,所以通过电子邮件发送他们的支持,询问是否有将Image指针转换为代码中的C#图像的方式,而无需先使用SDK将其保存到文件中。

他们提供我们用下面的函数(他们认为这没有经过测试,有人从字面上只是写它),我相信这就是这个错误是从周围的一切是非常基本的到来:

public void ProcessNewPreviewImage(IntPtr imageData, int imageWidth, int imageHeight) 
    { 
     try 
     { 
      if (realScanCapturing) 
      { 
       //______________________________________ 
       // Create byte[] to store the image data 
       byte[] templateRawData; 

       //________________________________________ 
       // Init the array to the size of this image 
       templateRawData = new byte[imageWidth * imageHeight]; 

       //____________________________________ 
       // Get the size of the image as a UINT 
       uint size = Convert.ToUInt32(imageWidth * imageHeight); 

       //__________________________________________________________ 
       // Copy the pointer image data to the byte[] we just created 
       CopyMemory(templateRawData, imageData, size); 

       //_____________________________________________________________________ 
       //Create a new bitmap object usign this preview images height and width 
       Bitmap tmpBmp = new Bitmap(imageWidth, imageHeight, System.Drawing.Imaging.PixelFormat.Format8bppIndexed); 

       //_________________________________________ 
       // Create the color palette for this bitmap 
       System.Drawing.Imaging.ColorPalette cp = tmpBmp.Palette; 
       for (int i = 0; i <= 255; i++) 
       { 
        cp.Entries[i] = Color.FromArgb(i, i, i); 
       } 

       //________________________________________ 
       // Assign this color palette to the bitmap 
       tmpBmp.Palette = cp; 

       //_________________________________________________________________ 
       // Create a new rectangle object using the dimensions of our bitmap 
       Rectangle rect = new Rectangle(0, 0, tmpBmp.Width, tmpBmp.Height); 

       //_____________________________________________________________________________ 
       // Create a BitmapData object (which will be used to modify the preview image?) 
       System.Drawing.Imaging.BitmapData tmpBMPData = null; 

       //________________________________________________________________________________________________ 
       // Locks the bitmap holding the preview image into memory so that we can change it programatically 
       tmpBMPData = tmpBmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, tmpBmp.PixelFormat); 

       //__________________________________________________________________________ 
       // Create new pointer pointing at the start of the image data we just locked 
       IntPtr ptr = tmpBMPData.Scan0; 

       //__________________________________________________________ 
       // Copy the raw template data to the pointer we just created 
       System.Runtime.InteropServices.Marshal.Copy(templateRawData, 0, ptr, imageWidth * imageHeight); 

       //__________________ 
       // Unlock the bitmap 
       tmpBmp.UnlockBits(tmpBMPData); 

       System.IO.MemoryStream msImage = new System.IO.MemoryStream(); 
       tmpBmp.Save(msImage, ImageFormat.Bmp); 

       byte[] byteImage = Util.ImageToByteArray(tmpBmp); 

       //______________________________ 
       // Send the extracted image data back to the client for display 
       thisClientServer.GetStreamingWcf(activeClientStation.VtServerDetails.ServerIpAddress, (int)activeClientStation.StreamingPort).StreamImage(byteImage); 


       tmpBmp.Dispose(); 
      } 
     } 
     catch (Exception ex) 
     { 
      ShowDebugMessage("Error in ProcessNewPreviewImage: " + ex.Message); 
     } 
    } 

这些评论已经被我自己添加了,因为我一直在试图理解这里实际发生的事情,我仍然不认为我完全理解他们在做什么。它确实有效,我在测试过程中没有遇到错误,但显然在长时间使用后会弹出此错误。

我希望有人能够更好地理解他们提供给我的代码,并突出显示可能导致问题的任何区域?

任何帮助表示赞赏! Registers Adrian

+0

你有什么要求,你现在使用大量的非托管内存,而不是那些漂亮的内存映射文件。不要在位图上调用Dispose()是垃圾收集器运行不够频繁时的典型情况。使用SysInternals的Process Explorer并观察进程的私有字节。 –

回答

0

我发现内存泄漏,最终。