我正在为 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;
}