I am useing the MODI (Office OCR) to do this. It is working like a charm for words, sentences, numbers and mixes of both. However - It fails if the image contains only one single character.
I have no idea why i fails, but since this is what you wanted to do, you should probably go for one of the other ocr solutions.
Is there anybody who knows why it fails with only one letter?
Here is my code:
Bitmap BWImage = new Bitmap(fileName);
System.Drawing.Imaging.BitmapData BWLockImage = BWImage.LockBits(new Rectangle(0, 0, BWImage.Width, BWImage.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, PixelFormat.Format1bppIndexed);
int imageSize = BWLockImage.Stride * BWLockImage.Height;
byte[] BWImageBuffer = new byte[imageSize];
Marshal.Copy(BWLockImage.Scan0, BWImageBuffer, 0, imageSize);
DoOCR(BWLockImage, BWImageBuffer, tmpPosRect, false);
public string DoOCR(System.Drawing.Imaging.BitmapData BWLockImage, byte[] BWImageBuffer, Rectangle iAusschnitt, bool isNumber)
{
Bitmap tmpImage = Bildausschnitt1bpp(BWLockImage, BWImageBuffer, iAusschnitt);
string file = Path.GetTempFileName();
string tmpResult = "";
try
{
tmpImage.Save(file, ImageFormat.Tiff);
_MODIDocument.Create(file);
_MODIDocument.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, false, false);
MODI.IImage myImage = (MODI.IImage)_MODIDocument.Images[0];
MODI.ILayout myLayout = (MODI.ILayout)myImage.Layout;
tmpResult = myLayout.Text;
}
catch
{
if (_MODIDocument != null)
{
_MODIDocument.Close(false);
_MODIDocument = null;
}
tmpImage.Dispose();
tmpImage = null;
GC.Collect();
File.Delete(file);
}
return tmpResult;
}