EmguCV Out of memory exception in x86 release mode only-Sharpening Images

穿精又带淫゛_ 提交于 2019-12-02 08:56:53

I think this is a different problem to the access violation one linked in the comments.

Convolve calls Filter2D in the underlying OpenCv API - which works on a single channel float image.

You are passing a multiple channel byte image.

Emgu 3.3 converts your input to a float image, calls Filter2D once per channel and stitches the images back together.

For 6000 x 4000 this needs to allocate about 576MB during the call, which would be a lot if you are running in a 32 bit process.

Edit:

Calling Filter2d on each channel and disposing as you go uses less memory, but will be a bit slower.

Example using OpenCvSharp which I'm more familiar with, overhead of the filtering is only 100mb:

    var inputMat = BitmapConverter.ToMat(myBitmap);
    var kernel = OpenCvSharp.InputArray.Create(
        new float[3, 3] { { 0, -1, 0 }, { -1, 5, -1 }, { 0, -1, 0 } }
        );

    for (int i = 0; i < inputMat.Channels(); i++)
    {
        var c1 = inputMat.ExtractChannel(i);
        var c2 = c1.Filter2D(inputMat.Type(), kernel);
        c1.Dispose();
        c2.InsertChannel(inputMat, i);
        c2.Dispose();
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!