Click here to Skip to main content
12,761,046 members (31,098 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#
I want to make and OCR project which recognizes a single character from and image(not a sentence from a document) in C#, can anyone help me out with some code? i was searching on internet about it, and i found 2-3 codes of OCR, but they were too difficult to understand, can anyone give me some simple code or some free library to do that thing.

Thanks in Advance
Posted 14-Feb-11 8:13am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

As you said you need to use OCR(Optical Character Recognition). There is no inbuilt func for OCR in C# but maybe using Microsoft Office Document Imaging Library (MODI) might be helpful. Check out these links;

How To: Use Office 2007 OCR Using C#[^][^]

OCR with Microsoft® Office[^]

The free librarys that you can use;
- Tesseract[^]

Espen Harlinn 14-Feb-11 15:53pm
Good links, my 5
SAKryukov 14-Feb-11 17:32pm
Pay attention, OP require C#. I know some good codes which I actually tried, please see my answer.
cYpH3r x3r0 15-Feb-11 1:29am
i m still pretty much confused because i want to use MODI and i dont know the proper procedure which must be followed... the link you gave me on MODI is not doubt very good, and i have downloaded it, but its giving me error that

The type or namespace name 'MODI' could not be found (are you missing a using directive or an assembly reference?)

i know i have to give some referrence to make it work, but i dont know "what referrence"?
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Tesseract and GOCR are not easy to use and not so good; Office is proprietary, not always available.

Thsre is C# binding for Tesseract called Tessnet:[^].

There are some good works on CodeProjects. I think they are better but need to be completed. Basic and most difficult work is done. As you mentioned "single character", one of them must be ideal for you (I tried them out). See: Neural Network OCR[^] (this one is one of the best), Creating Optical Character Recognition (OCR) applications using Neural Networks[^], OCR Line Detection[^], Unicode Optical Character Recognition[^] (this one is one of the best).

Good luck,
Nishant Sivakumar 14-Feb-11 17:36pm
Voted 5.
SAKryukov 14-Feb-11 17:39pm
Thank you.
As I tried the codes, I'm pretty sure they can make a product. The cores (neural stuff) are healthy.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

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:

// Load Image from File
Bitmap BWImage = new Bitmap(fileName);
// Lock destination bitmap in memory
System.Drawing.Imaging.BitmapData BWLockImage = BWImage.LockBits(new Rectangle(0, 0, BWImage.Width, BWImage.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, PixelFormat.Format1bppIndexed);

// Copy image data to binary array
int imageSize = BWLockImage.Stride * BWLockImage.Height;
byte[] BWImageBuffer = new byte[imageSize];
Marshal.Copy(BWLockImage.Scan0, BWImageBuffer, 0, imageSize);
DoOCR(BWLockImage, BWImageBuffer, tmpPosRect, false);

// Do the OCR with this function
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 = "";
        tmpImage.Save(file, ImageFormat.Tiff);
        // Modi parameter erstellen
        _MODIDocument.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, false, false);

        MODI.IImage myImage = (MODI.IImage)_MODIDocument.Images[0]; //first page in file
        MODI.ILayout myLayout = (MODI.ILayout)myImage.Layout;
        tmpResult = myLayout.Text;
        if (_MODIDocument != null)
            _MODIDocument.Close(false); //Closes the document and deallocates the memory.
            _MODIDocument = null;
        // Bild freigeben
        tmpImage = null;
        // Garbage Collector ausführen
        // Bilddatei löschen
    return tmpResult;
Amol000 21-Jun-12 1:16am
i have got ocr running error... plz help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170217.1 | Last Updated 5 Sep 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100