我正在开发一个 anpr 应用程序,我已经设法从车辆图像中找到车牌区域。
当我将此图像提供给 tesseract OCR 引擎时,它似乎在“C”之前检测到字符“L”,因此我正在考虑取出车牌区域周围剩余的黑色像素。我可以采取一种特殊的方法来解决这个问题吗?在这种情况下,我使用的是 aforge.net 库
干杯
最佳答案
半自动去除车牌周围黑色像素区域的一种方法是应用 PointedColorFloodFill过滤四次,将洪水填充起点放在图像的四个角。
这是一些示例代码,我在上面的问题中对车牌图像的副本应用了过滤器(裁剪以删除白色边框):
var filter = new PointedColorFloodFill();
filter.FillColor = Color.White;
filter.Tolerance = Color.FromArgb(60, 60, 60);
filter.StartingPoint = new IntPoint(0, 0);
filter.ApplyInPlace(image);
filter.StartingPoint = new IntPoint(image.Size.Width - 1, 0);
filter.ApplyInPlace(image);
filter.StartingPoint = new IntPoint(image.Size.Width - 1, image.Size.Height - 1);
filter.ApplyInPlace(image);
filter.StartingPoint = new IntPoint(0, image.Size.Height - 1);
filter.ApplyInPlace(image);
完成四个角的过滤后提供如下图像:
您可能想尝试使用更灰的填充颜色和不同的容差,但此示例至少可以提供一个合理的起点。
更新 我偶然发现了 BradleyLocalThresholding过滤器可以为您的 OCR 识别提供更好的起点。此滤镜只能应用于 8bpp 图像,您可以先应用 Grayscale 来解决这个问题对原始图像进行过滤。如果在 PointedColorFloodFill
代码之前添加以下四行:
var grayFilter = new Grayscale(0.3, 0.3, 0.3);
var image = grayFilter.Apply(originalImage);
var bradleyfilter = new BradleyLocalThresholding();
bradleyfilter.ApplyInPlace(image);
并将 PointedColorFloodFill
容差降低到例如每个 RGB 分量 10 个:
filter.Tolerance = Color.FromArgb(10, 10, 10);
完全过滤后的车牌现在看起来像这样:
关于c# - 从车辆图像中提取车牌,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11794943/