Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Hello,
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 7:13am
Rate this: bad
good
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#[^]
 
http://www.devsource.com/c/a/Languages/Using-The-Office-2007-OCR-Component-in-C/[^]
 
OCR with Microsoft® Office[^]
 
The free librarys that you can use;
- Tesseract
http://code.google.com/p/tesseract-ocr/[^]
 
-GOCR
[^]
  Permalink  
Comments
Espen Harlinn at 14-Feb-11 15:53pm
   
Good links, my 5
SAKryukov at 14-Feb-11 17:32pm
   
Pay attention, OP require C#. I know some good codes which I actually tried, please see my answer.
--SA
cYpH3r x3r0 at 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
good
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: http://www.pixel-technology.com/freeware/tessnet2/[^].
 
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,
—SA
  Permalink  
Comments
Nishant Sivakumar at 14-Feb-11 17:36pm
   
Voted 5.
SAKryukov at 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.
--SA
Rate this: bad
good
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 = "";
    try
    {
        tmpImage.Save(file, ImageFormat.Tiff);
        _MODIDocument.Create(file);
        // 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;
    }
    catch
    {
        if (_MODIDocument != null)
        {
            _MODIDocument.Close(false); //Closes the document and deallocates the memory.
            _MODIDocument = null;
        }
        // Bild freigeben
        tmpImage.Dispose();
        tmpImage = null;
        // Garbage Collector ausführen
        GC.Collect();
        // Bilddatei löschen
        File.Delete(file);
    }
    return tmpResult;
}
  Permalink  
Comments
Amol000 at 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
0 OriginalGriff 389
1 Nirav Prabtani 268
2 Richard Deeming 250
3 _Amy 185
4 CHill60 170
0 OriginalGriff 8,104
1 Sergey Alexandrovich Kryukov 7,067
2 Maciej Los 4,039
3 Peter Leow 3,738
4 CHill60 2,912


Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 5 Sep 2011
Copyright © CodeProject, 1999-2014
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