Today I started using Tesseract to parse portions of my screen for numbers. I have had a decent amount of success with larger text (which results in a higher resolution image). Now I am trying to use Tesseract in a more practical sense and the image quality is too low. I have tried increasing the resolution and redrawing with anti-aliasing, but I am not sure if I am even doing these things right. Do you have any suggestions as to how I might be able to get Tesseract to recognize the "12" in my tiny image?
Image: 
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
}
I suggest using image processing methodes to improve the accuracy of tesseract-ocr. I use OpenCV libraries in c++ for this.
So let's take your image and rescale it by +500%:

You can see the image is getting a bit pixely. In this case you want to smooth the edges by using a Gaussian filter. I used a Gaussian filter with a kernal size of 3x3:

The last thing you need to do is segmentation of the digits by using a threshold:

Running tesseract on the segmented image using the digit whitelist will result in "12".
Hope this helped. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With