Tesseract OCR引擎无法从自动生成的图像中读取文本,但可以从MS Paint中的CUT读取

我正在为Tesseract OCR引擎使用.NET包装器。 我有一个大型文档是PNG。 当我在MS油漆中切出一段图像然后将其送入引擎时,它可以工作。 但是当我在代码中执行此操作时,引擎无法识别图像中的文本。 图像看起来相同,并且属性不会显得非常偏离。 所以我有点困惑。

这是两张图片。 来自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; } 

新Bitmap的默认分辨率为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; }