I am using OCR to recognize digits on picture
var engine = new TesseractEngine(@"C:\Projects\tessdata", "eng", EngineMode.Default,);
var currentImage = TakeScreen();
var page = engine.Process(ScaleByPercent(currentImage, 500));
var text = page.GetText().Replace("\n", "");
Scale:
public Bitmap ScaleByPercent(Bitmap imgPhoto, int Percent)
{
float nPercent = ((float)Percent / 100);
int sourceWidth = imgPhoto.Width;
int sourceHeight = imgPhoto.Height;
var destWidth = (int)(sourceWidth * nPercent);
var destHeight = (int)(sourceHeight * nPercent);
var bmPhoto = new Bitmap(destWidth, destHeight,
PixelFormat.Format24bppRgb);
bmPhoto.SetResolution(imgPhoto.HorizontalResolution,
imgPhoto.VerticalResolution);
Graphics grPhoto = Graphics.FromImage(bmPhoto);
grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic;
grPhoto.DrawImage(imgPhoto,
new System.Drawing.Rectangle(0, 0, destWidth, destHeight),
new System.Drawing.Rectangle(0, 0, sourceWidth, sourceHeight),
GraphicsUnit.Pixel);
bmPhoto.Save(@"D:\Scale.png", System.Drawing.Imaging.ImageFormat.Png);
grPhoto.Dispose();
return bmPhoto;
}
But i get result "10g".
You can tell the Tesseract Engine to only look for digits by using the following code :
var engine = new TesseractEngine(@"C:\Projects\tessdata", "eng", EngineMode.Default);
engine.SetVariable("tessedit_char_whitelist", "0123456789");
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