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.
- Improve OCR color image reading quality
- Distinguish between ocr region types
- Clean up after text translation
- Cancel OCR in progress
- Count total number of each word in images
- Font Mapping
- More image OCR Recognition functions
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.)
- Run Microsoft Visual Studio (2005 or later version);
- Create a project with programming language - Visual C#;
- Add RasterEdge.DotNetImaging.dll & RasterEdge.DotNetImaging.Ocr.dll to your Visual C# applications;
- Call RasterEdge .NET Image Namespace:
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.