Skip to content

How can I set the font to read from OCR?

venkata narayana

Asked Feb 6, 2013, 10:54 PM EST1 answer
Share
LinkedInX

Hi Experts,

I am trying to read text from image file. If my image contains plain English words, it gives me nice output.
But when my image file has different font, it is giving me wrong output.

How can I set the font to read from OCR? 

  MODI.Document ModiObj = new MODI.Document();
                ModiObj.Create(ImagePath);
                ModiObj.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, true, true);

                //Retrieve the text gathered from the image
                MODI.Image ModiImageObj = (MODI.Image)ModiObj.Images[0];
                

                // Store Image Content in Text File
                FileStream CreateFileObj = new FileStream(StoreTextFilePath, FileMode.Create);
                //save the image text in the text file 
                StreamWriter WriteFileObj = new StreamWriter(CreateFileObj);
                WriteFileObj.Write(ModiImageObj.Layout.Text);
                WriteFileObj.Close();

                ModiObj.Close(false);

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Here is an online articel on OCR reader within c sharp class, including its features and text reading using detailed, which contains how to set the font to read OCR.


    C#
    string fileName = FolderName + "SampleOCR.bmp";
    
                Bitmap bmp = new Bitmap(fileName);
    
                Tesseract ocr = new Tesseract();
                //set the "tessdata" folder's parent folder
                ocr.Init(@"C:\", "eng", false);
                List<Word> result = ocr.DoOCR(bmp, Rectangle.Empty);
    
                foreach (Word word in result)
                {
                    Debug.WriteLine(word.Confidence + ": " + word.Text + " (" + word.Left + ", " + word.Top + ")"
                        + " W=" + (word.Right - word.Left) + ", H=" + (word.Bottom - word.Top));
                }
    
                Bitmap newBmp = new Bitmap(bmp.Width, bmp.Height, bmp.PixelFormat);
                Graphics g = Graphics.FromImage(newBmp);
                g.DrawImage(bmp, 0, 0);
    
                foreach (Word word in result)
                {
                    g.DrawRectangle(new Pen(new SolidBrush(Color.Red)),
                        new Rectangle(word.Left, word.Top, (word.Right - word.Left), (word.Bottom - word.Top)));
                }
    
                newBmp.Save(fileName + ".new.bmp");
    
                int lineCount = Tesseract.LineCount(result);
                Debug.WriteLine("Line Count: " + lineCount);
                for (int i = 0; i < lineCount; i++)
                {
                    String val = Tesseract.GetLineText(result, i);
                    Debug.WriteLine("Line " + i + ": " + val);
                }
    0