【问题标题】:The Tesseract OCR engine isn't able to read the text from an auto generated image, but can from a CUT in MS PaintTesseract OCR 引擎无法从自动生成的图像中读取文本,但可以从 MS Paint 中的 CUT 中读取
【发布时间】:2013-05-14 09:09:59
【问题描述】:

我正在为 Tesseract OCR 引擎使用 .NET 包装器。我有一个很大的 PNG 文件。当我在 MS Paint 中剪下一段图像,然后将其输入引擎时,它就可以工作了。但是当我在代码中执行此操作时,引擎无法识别图像中的文本。图像看起来相同,属性看起来也不是很差。所以我有点困惑。

这是两张图片。来自 MS 油漆:

来自代码:

这是我从 MS 绘制图像中得到的:

通过代码:

它们真的很相似所以我不确定为什么它无法识别第二个文本。以下是我生成图像的方式。

public Bitmap CropImage(Bitmap source, Rectangle section)
    {
        Bitmap bmp = new Bitmap(section.Width, section.Height);
        Graphics g = Graphics.FromImage(bmp);
        g.DrawImage(source, 0, 0, section, GraphicsUnit.Pixel);

        return bmp;
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        Bitmap source = new Bitmap(test);
        Rectangle section = new Rectangle(new Point(78, 65), new Size(800, 50));
        Bitmap CroppedImage = CropImage(source, section);
        CroppedImage.Save(@"c:\users\user\desktop\test34.png", System.Drawing.Imaging.ImageFormat.Png);

        this.pictureBox1.Image = CroppedImage;
    }

【问题讨论】:

  • 你能显示你调用 Tesseract 的代码吗?可能是 Tesseract ocr 从命令行正确执行,但在被包装器调用时却没有。
  • @AruniRC Here's 代码。我没有对演示项目进行任何更改。

标签: c# image-processing bitmap ocr tesseract


【解决方案1】:

新位图的默认分辨率为 96 DPI,这对于 OCR 目的来说是不够的。尝试提高到 300 DPI,如:

bmp.SetResolution(300, 300);

更新 1:当您缩放图像时,其尺寸也会发生变化。这是一个示例 rescale 函数:

public static Image Rescale(Image image, int dpiX, int dpiY)
{
    Bitmap bm = new Bitmap((int)(image.Width * dpiX / image.HorizontalResolution), (int)(image.Height * dpiY / image.VerticalResolution));
    bm.SetResolution(dpiX, dpiY);
    Graphics g = Graphics.FromImage(bm);
    g.InterpolationMode = InterpolationMode.Bicubic;
    g.PixelOffsetMode = PixelOffsetMode.HighQuality;
    g.DrawImage(image, 0, 0);
    g.Dispose();

    return bm;
}

【讨论】:

  • 嗯...有什么具体的方法我需要更改分辨率吗?我调用了 SetResolution,然后保存了图像。但是,该文件看起来相同。同样大小和一切。我什至尝试将其更改为 (1000, 1000)。 OCR 引擎仍然无法识别它。我认为它根本没有改变位图。
  • test 图像包裹在新位图中也会将分辨率更改为 96 DPI。
  • 所以,我用它来反映图像的变化。但是,随着数量的增加,图像会变小。所以我反过来把它从 96.0F 降低到 80.0F,然后是 50.0F。什么都没有被识别出来。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多