Program to Extract Text from Image using Tesseract in C#

Rajnilari2015
Posted by Rajnilari2015 under C# category on | Points: 40 | Views : 1523
using System;
using Tesseract;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var testImagePath = [YOUR IMAGE PATH];
var dataPath = [YOUR DATA PATH];

try
{
using (var tEngine = new TesseractEngine(dataPath, "eng", EngineMode.Default)) //creating the tesseract OCR engine with English as the language
{
using (var img = Pix.LoadFromFile(testImagePath)) // Load of the image file from the Pix object which is a wrapper for Leptonica PIX structure
{
using (var page = tEngine.Process(img)) //process the specified image
{
var text = page.GetText(); //Gets the image's content as plain text.
Console.WriteLine(text); //display the text
Console.WriteLine(page.GetMeanConfidence()); //Get's the mean confidence that as a percentage of the recognized text.
Console.ReadKey();
}
}
}
}
catch (Exception e)
{
Console.WriteLine("Unexpected Error: " + e.Message);
}
}
}
}

Comments or Responses

Login to post response