This works but the results atleast with the font I tried to use it on were quite inaccurate. I found that by scaling up the source image it gives better results but still not accurate enough for the font I were dealing with. To overcome this I fortunately were able to use edit distance to pick what was the most likely word from a set of words.
static string AnalyzeImage(string filename)
{
MODI.Document doc = new Document();
doc.Create(filename);
doc.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, false, false);
//doc.Save();
MODI.Image img = (MODI.Image)doc.Images[0];
return img.Layout.Text;
}
static void CropImageAndSaveAsDestPNG(string fullname)
{
Rectangle croparea = new Rectangle(137, 24, 200, 20);
Bitmap image = new Bitmap(fullname);
Bitmap b = image.Clone(croparea, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
Bitmap r = ScaleByPercent(b, 500);
r.Save("dest.png", System.Drawing.Imaging.ImageFormat.Png);
image.Dispose(); b.Dispose(); r.Dispose();
}
static Bitmap ScaleByPercent(Bitmap imgPhoto, int Percent)
{
float nPercent = ((float)Percent / 100);
int sourceWidth = imgPhoto.Width;
int sourceHeight = imgPhoto.Height;
int sourceX = 0; int sourceY = 0;
int destX = 0; int destY = 0;
int destWidth = (int)(sourceWidth * nPercent);
int destHeight = (int)(sourceHeight * nPercent);
Bitmap bmPhoto = new Bitmap(destWidth, destHeight, PixelFormat.Format24bppRgb);
bmPhoto.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution);
Graphics grPhoto = Graphics.FromImage(bmPhoto);
grPhoto.InterpolationMode = InterpolationMode.High;
grPhoto.DrawImage(imgPhoto, new Rectangle(destX, destY, destWidth, destHeight), new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight), GraphicsUnit.Pixel);
grPhoto.Dispose();
return bmPhoto;
}
Couple C# edit distance implementations: