Coffeehouse Thread

6 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.


Back to Forum: Coffeehouse
  • User profile image

    Does anyone know of any .NET code or class that will do optical character recognition from an image?

    Specifically I want to take a screen shot and then try to capture some of the text on the screen.    Kind of like a screen scrape. 

    My preference would be something in c# also.    I did a search and came across an open source project called GOCR but I could find any .NET flavors of it.  Do you know of any?


  • User profile image

    I was looking for the same thing a while ago, but all I could find was some commercial library. It might have worked, but I couldn't get the free trial to work.

    Fortunately, the only text I needed to recognize was all in the same font and size, on a white background. So I just grabbed images of all characters and hacked one together myself.

  • User profile image

    Its a screen scrape of a game, so the text that is rendered will always be the same, but the background will be different.  The text color is pretty consistent so maybe I could extract the color and then do some type of bitmap comparison.


  • User profile image

    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.

    The OCR interop dll is from here I believe:

    static string AnalyzeImage(string filename)
    MODI.Document doc = new Document();
    doc.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, false, false);
    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);
    return bmPhoto;

  • User profile image

    Although not in .NET, I found the COM+ library of MODI(Microsoft Office Document Imaging) works well provided the resolution is not too small and the background is not too colorful. Smiley

    If it's inhouse application, I think that'd be quite enough.

    Recent Achievement unlocked: Code Avenger Tier 4/6: You see dead program. A lot!
    Last modified
  • User profile image

    I think I may have found a solution.  Although it might take a fair amount of work.  Combine the following two projects

    and also figure out how to do a screen capture in .NET

    I am suprised that there isn't already a solution out in the wild.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.