循环和位图:循环时如何处理emgu图像(Of bgr,byte)?

时间:2017-09-24 04:01:02

标签: image bitmap dispose emgucv

在for ... next循环中,如何处理位图和图像?

特别是image(of bgr, byte)张图片。

"图像(bgr,字节)"图像来自emgu库。

当您处理单个位图或图像时,Dispose()命令可正常工作。

但是当您循环浏览多个图像时,会发生Outofmemory错误。

即使应用using ... end using命令,也会出现内存问题。

例如,这会给我带来内存错误:

Dim pic As Bitmap = New Bitmap(270, 100)
For i = 0 to 100
    Dim CleanImage As New Image(Of Bgr, Byte)(pic)

    'this command comes from the emgu library - tesseract
    OCRz.Recognize(CleanImage)    

    CleanImage.Dispose()

Next

将会:

Dim pic As Bitmap = New Bitmap(270, 100)
For i = 0 to 100
    Using CleanImage As New Image(Of Bgr, Byte)(pic)  
        OCRz.Recognize(CleanImage)    
    End Using
Next

我已经尝试GC.Collect()了。这没有用。

如何正确摆脱这些烦人的位图和图像的程序?

我迫切希望找到解决方案。

emgu wiki声明如下:

  

自动垃圾收集Image类   自动处理内存管理和垃圾   集合。

     

一旦垃圾收集器确定没有更多的引用   在Image对象中,它将调用Disposed方法,   它释放了非托管的IplImage结构。

     

垃圾收集器决定处理图像的时间不是   保证。使用大图像时,建议拨打电话   Dispose()方法显式释放对象。或者,使用   C#中的using关键字用于限制图像的范围

using (Image<Gray, Single> image = new Image<Gray, Single>(1000, 800))

 {  

        ... //do something here in the image 

 } //The image will be disposed here and memory freed

这正是我正在做的事情。然而,我收到了这个OutOfMemory异常。发生了什么事?

0 个答案:

没有答案
相关问题