OCR Recognition in C#.NET

Comprehensive Visual C# Codes for OCR Recognition within .NET Imaging SDK

If you want to deploy OCR recognition, RasterEdge OCR add-on is the best choice. Flexible OCR recognition, detecting and processing options are provided for a better performance.
OCR Recognition
This guide tells users how to OCR images with RasterEdge .NET Imaging SDK and OCR add-on using Visual C# sample codes. (For VB.NET developers, please go to OCR Recognition for VB.NET. Want to view Image and document in Winforms or Web applications, please go to OCR Recognition in Winforms and Web Document Image OCR Recognition.)

using System.Drawing;
using System.Diagnostics;
using RasterEdge.Imaging.TesseractOCR;

Extract Text from Image Method

The following code shows how to extract text from tmage using Rasteredge .NET Image SDK

public List<Word> DoOCR(Bitmap bitmap);
public List<Word> DoOCR(REImage image);
public List<Word> DoOCR(Bitmap bitmap, Rectangle rect);
public List<Word> DoOCR(REImage image, Rectangle rect);

Extract Text from Image Example

The following code shows how to extract text from tmage using Rasteredge .NET Image SDK method.

public static void ReadWordFromImage()
{
string fileName = FolderName + "SampleOCR.bmp";

Bitmap bmp = new Bitmap(fileName);

Tesseract ocr = new Tesseract();
ocr.Init(@"C:\", "eng", false);//set the "tessdata" folder's parent folder
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);
}

}

More Tutorials!
Find more user guides with RasteEdge .NET Image SDK using Visual C# sample codings!
Want to install Imaging SDK in Winforms or Web applications, please go to Use Imaging SDK in Winforms and Web Document Image Viewer.