aforge.net中的过滤器不支持源像素格式

Ehs*_*bar 2 c# image bitmap image-processing accord.net

我正在尝试使用开发LPR系统Aforge.net,我想对图像应用滤镜,如下所示:

            Bitmap a = new Bitmap(@"C:\Users\Public\Pictures\Sample Pictures\1.png");
            SobelEdgeDetector filter = new SobelEdgeDetector();
            filter.ApplyInPlace(a);
            pictureBox1.Image = a;
Run Code Online (Sandbox Code Playgroud)

但是运行后我得到了这个错误:

Source pixel format is not supported by the filter.
Run Code Online (Sandbox Code Playgroud)

我在aforge.net中是新手。

And*_*son 5

正如你可以看到从这个 API文档页面,该SobolEdgeDetector过滤器只支持8bpp的灰度图像。

因此,要应用滤镜,您需要首先将图像转换为8bpp并转换为灰度,例如:

Bitmap a = AForge.Imaging.Image.Clone(
    new Bitmap(@"C:\Users\Public\Pictures\Sample Pictures\1.png"),
    PixelFormat.Format8bppIndexed);
AForge.Imaging.Image.SetGrayscalePalette(a);
Run Code Online (Sandbox Code Playgroud)