简体   繁体   English

使用AFORGE.NET ProcessImage的OutOfMemoryException

[英]OutOfMemoryException using AFORGE.NET ProcessImage

I have a large System.Drawing.Bitmap (14399 X 10799) that I am trying to process using AFORGE.NET. 我有一个试图使用AFORGE.NET处理的大型System.Drawing.Bitmap(14399 X 10799)。 My algorithm works very well with a smaller image but with this size of image I receive an OutOfMemoryException when I call Process(). 我的算法在较小的图像上效果很好,但是在此尺寸的图像上,我调用Process()时会收到OutOfMemoryException。

Before calling Process(), my task manager reports that the application is using 613MB, at the time of the exception, it is using 609MB. 在调用Process()之前,我的任务管理器报告该应用程序正在使用613MB,在发生异常时,它正在使用609MB。

I have tried setting my platform target to x64 but this does not seem to affect the occurence of the exception. 我尝试将平台目标设置为x64,但这似乎并不影响异常的发生。

I suspect that the exception is not related to the memory but something else, how can I circumvent it? 我怀疑异常与内存无关,而是其他原因,我该如何规避呢?

// lock image
        BitmapData bitmapData = bitmap.LockBits(
            new Rectangle(0, 0, bitmap.Width, bitmap.Height),
            ImageLockMode.ReadWrite, bitmap.PixelFormat);

        // step 1 - turn background to black
        ColorFiltering colorFilter = new ColorFiltering();

        colorFilter.Red = new IntRange(0, 64);
        colorFilter.Green = new IntRange(0, 64);
        colorFilter.Blue = new IntRange(0, 64);
        colorFilter.FillOutsideRange = false;

        colorFilter.ApplyInPlace(bitmapData);

        // step 2 - locating objects
        BlobCounter blobCounter = new BlobCounter();

        blobCounter.FilterBlobs = true;
        blobCounter.MinHeight = 5;
        blobCounter.MinWidth = 5;

        blobCounter.ProcessImage(bitmapData); //Crash
        Blob[] blobs = blobCounter.GetObjectsInformation();
        bitmap.UnlockBits(bitmapData);

Exception of type 'System.OutOfMemoryException' was thrown. 引发了类型为'System.OutOfMemoryException'的异常。

The memory usage could be quite high if your image contains a lot of blobs. 如果您的图像包含大量斑点,则内存使用量可能会很高。 Have you tried with a blank image of the same size ? 您是否尝试过使用相同尺寸的空白图像?

If it is really caused by your image having too many blobs, you could try to add more constraints on your blob filtering. 如果确实是由于图像中的斑点太多,则可以尝试对斑点过滤添加更多约束。

i had simillar issue, just use the ResizeBilinear filter or any other resize filter in Aforge.Imaging.Filters (you don't need the full quality image if you are processing it just to get some information)and any modification you want to make for the source image it's done by scaling back the points for objects you found and below is a simple method to get a temporary scaled down image for processing 我有类似的问题,只需在Aforge.Imaging.Filters中使用ResizeBilinear过滤器或任何其他调整大小的过滤器(如果您只是为了获取一些信息就不需要完整质量的图像)以及想要进行的任何修改通过缩小找到的对象的点来完成源图像,下面是获得临时缩小图像以进行处理的简单方法

 Bitmap ResizeMyImage(Bitmap Source, int scalefactor)
        {
            int newHeight = Source.Height / scalefactor;
            int newWidth = (int)(Source.Width * (newHeight / (float)Source.Height));
            ResizeBilinear filter = new ResizeBilinear(newWidth, newHeight);
            return filter.Apply(Source);
        }

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

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