今天我开始使用Tesseract来解析部分屏幕上的数字。我用较大的文本获得了相当大的成功(这导致了更高分辨率的图像)。现在我试图在更实际的意义上使用Tesseract,图像质量太低。我尝试过增加分辨率并使用抗锯齿重绘,但我不确定我是否正在做这些事情。你有什么建议我可以让Tesseract在我的小图片中识别出“12”吗?
图片:
static public void test()
{
string readIn;
TesseractEngine engine = new TesseractEngine(@".\tessdata","eng", EngineMode.Default);
engine.SetVariable("tessedit_char_whitelist", "0123456789"); //only read as numbers
Rectangle rect = new Rectangle(181, 107, 25, 25);
Bitmap bmp = new Bitmap(rect.Width, rect.Height, PixelFormat.Format32bppArgb);
Graphics g = Graphics.FromImage(bmp);
g.CopyFromScreen(rect.Left, rect.Top, 0, 0, bmp.Size, CopyPixelOperation.SourceCopy);
g.InterpolationMode = InterpolationMode.High;
g.CompositingQuality = CompositingQuality.HighQuality;
g.SmoothingMode = SmoothingMode.AntiAlias;
g.DrawImage(bmp, rect.Width, rect.Height); //Do some anti-aliasing hopefully?
bmp.SetResolution(300, 300) //Try increasing resolution??
bmp.Save(@".\tmp.jpg");
readIn = engine.Process(PixConverter.ToPix(bmp)).GetText();
Console.WriteLine("This is what was read: " + readIn); //Empty
}