Test in a live environment
Test in production without watermarks.
Works wherever you need it to.
Developers frequently have to choose between the Tesseract OCR tool and the Microsoft OCR engine when it comes to Optical Character Recognition (OCR) in C#. Despite having different capabilities, efficiency, integration, and ease, both are effective OCR tools for extracting text from photos or scanned documents. Within the framework of C# development, we will thoroughly examine the merits, drawbacks, and applicability of different OCR tools like Tesseract vs. Microsoft OCR in this article.
Optical Character Recognition is referred to as OCR. It's a technology that makes it possible to turn various document formats—like scanned image documents, PDF files, or digital camera photos—into editable and searchable data. To transform an image's forms and patterns into machine-readable text, different OCR tools such as Google Cloud Vision or Google Vision OCR analyze the images. By using this technique, users may fetch text from photographs and edit, search, and change the content just like they would with a digital document.
Tesseract OCR is an open-source optical character recognition (OCR) engine, sometimes referred to as just Tesseract. Tesseract, which was initially created by Hewlett-Packard Laboratories in the 1980s and is now maintained by Google, is one of the most popular OCR engines in use today.
Tesseract's primary function is to identify text included in pictures or handling scanned documents and translate them into machine-readable text. This makes text editable, searchable, and manipulable by allowing users to extract text from a variety of sources, including scanned document analysis, photos, and PDF files.
Installing Tesseract OCR on your computer is the first step. The official Tesseract GitHub repository is where you can get the Tesseract installer: https://github.com/tesseract-ocr/tesseract.
To install Tesseract OCR on your computer, follow the setup instructions that are specific to your operating system (Windows, macOS, or Linux). After Tesseract OCR is installed, use Visual Studio's NuGet Package Manager to add the Tesseract.NET wrapper to your C# project.
Navigate to Tools -> NuGet Package Manager -> Manage NuGet Packages for Solution after opening your C# project in Visual Studio. You should be able to locate the package named "Tesseract" or "Tesseract.NET" by searching for "Tesseract" in the NuGet Package Manager. To include the package in your project, choose it and click Install.
You must set up Tesseract in your C# project to specify the location of the Tesseract OCR executable and language data files after installing the Tesseract.NET wrapper. Here's an example:
using Tesseract;
class Program
{
static void Main(string [] args)
{
using (var engine = new TesseractEngine(@"path_to_tesseract_folder", "eng", EngineMode.Default))
{
using (var img = Pix.LoadFromFile("image.png"))
{
using (var page = engine.Process(img))
{
var text = page.GetText();
Console.WriteLine(text);
}
}
}
}
}
using Tesseract;
class Program
{
static void Main(string [] args)
{
using (var engine = new TesseractEngine(@"path_to_tesseract_folder", "eng", EngineMode.Default))
{
using (var img = Pix.LoadFromFile("image.png"))
{
using (var page = engine.Process(img))
{
var text = page.GetText();
Console.WriteLine(text);
}
}
}
}
}
Imports Tesseract
Friend Class Program
Shared Sub Main(ByVal args() As String)
Using engine = New TesseractEngine("path_to_tesseract_folder", "eng", EngineMode.Default)
Using img = Pix.LoadFromFile("image.png")
Using page = engine.Process(img)
Dim text = page.GetText()
Console.WriteLine(text)
End Using
End Using
End Using
End Sub
End Class
To accomplish this, provide the location of your Tesseract installation directory and the language or languages you wish to utilize in the TesseractEngine constructor options. Replace "eng" with the language code for the language or languages you wish to use (e.g., "eng" for English) and "path_to_tesseract_folder" with the actual path to your Tesseract installation directory.
After setting up Tesseract in your C# project, you can now utilize its OCR features to extract text from pictures. The TesseractEngine instance can be used to process a picture once it has been loaded using the Pix class to extract text or run OCR on an image file, replacing "image.png" with the path of the image file.
Microsoft's Cognitive Services package includes Microsoft OCR, sometimes referred to as Microsoft Optical Character Recognition. Microsoft Azure offers a cloud-based optical character recognition (OCR) solution that can extract text from documents and photos with enhanced text recognition capabilities. Microsoft OCR uses deep neural networks and machine learning techniques to recognize text from a variety of sources with excellent accuracy.
You must combine Microsoft OCR with Azure Cognitive Services—more especially, the Computer Vision API—to use it in a C# project. This is how you can begin:
You must create an Azure account if you don't already have one. You can create a free Azure account and have access to several services during the trial time.
The Computer Vision service in Azure Cognitive Services must be configured when you have an Azure account.
Utilizing Microsoft Azure is possible. To communicate with the Computer Vision API in your C# project, use the CognitiveServices.Vision.ComputerVision NuGet package.
Navigate to Tools -> NuGet Package Manager then Manage NuGet Packages for Solution after opening your C# project in Visual Studio.
Install the package by doing a search for "Microsoft.Azure.CognitiveServices.Vision.ComputerVision".
After installing the SDK, you may use the Computer Vision API to do OCR. An introductory example of using the Computer Vision API to do OCR on an image can be found below:
using System;
using Microsoft.Azure.CognitiveServices.Vision.ComputerVision;
using Microsoft.Azure.CognitiveServices.Vision.ComputerVision.Models;
class Program
{
static async System.Threading.Tasks.Task Main(string [] args)
{
var endpoint = "YOUR_ENDPOINT";
var subscriptionKey = "YOUR_SUBSCRIPTION_KEY";
var client = new ComputerVisionClient(new ApiKeyServiceClientCredentials(subscriptionKey))
{
Endpoint = endpoint
};
var result = await client.RecognizeTextAsync("image.png", TextRecognitionMode.Printed);
foreach (var region in result.Regions)
{
foreach (var line in region.Lines)
{
foreach (var word in line.Words)
{
Console.WriteLine(word.Text);
}
}
}
}
}
using System;
using Microsoft.Azure.CognitiveServices.Vision.ComputerVision;
using Microsoft.Azure.CognitiveServices.Vision.ComputerVision.Models;
class Program
{
static async System.Threading.Tasks.Task Main(string [] args)
{
var endpoint = "YOUR_ENDPOINT";
var subscriptionKey = "YOUR_SUBSCRIPTION_KEY";
var client = new ComputerVisionClient(new ApiKeyServiceClientCredentials(subscriptionKey))
{
Endpoint = endpoint
};
var result = await client.RecognizeTextAsync("image.png", TextRecognitionMode.Printed);
foreach (var region in result.Regions)
{
foreach (var line in region.Lines)
{
foreach (var word in line.Words)
{
Console.WriteLine(word.Text);
}
}
}
}
}
Imports System
Imports Microsoft.Azure.CognitiveServices.Vision.ComputerVision
Imports Microsoft.Azure.CognitiveServices.Vision.ComputerVision.Models
Friend Class Program
Shared Async Function Main(ByVal args() As String) As System.Threading.Tasks.Task
Dim endpoint = "YOUR_ENDPOINT"
Dim subscriptionKey = "YOUR_SUBSCRIPTION_KEY"
Dim client = New ComputerVisionClient(New ApiKeyServiceClientCredentials(subscriptionKey)) With {.Endpoint = endpoint}
Dim result = Await client.RecognizeTextAsync("image.png", TextRecognitionMode.Printed)
For Each region In result.Regions
For Each line In region.Lines
For Each word In line.Words
Console.WriteLine(word.Text)
Next word
Next line
Next region
End Function
End Class
To perform OCR on an image file, substitute "image.png" in the code sample above with the path to the image file. This code will retrieve the recognized text from the image by sending it to the Computer Vision API. The endpoint URL and subscription key you received after configuring the Computer Vision service in Azure Cognitive Services should be substituted for "YOUR_ENDPOINT" and "YOUR_SUBSCRIPTION_KEY".
Developers may incorporate text recognition capabilities into their C# or VB.NET applications with IronOCR, a .NET OCR library. It offers a user-friendly API for text extraction from PDFs, pictures, and other types of media. Iron Software, a software development business that specializes in .NET components and libraries, creates and maintains IronOCR.
Here is a basic C# example:
var Ocr = new IronTesseract(); // nothing to configure
Ocr.Language = OcrLanguage.EnglishBest;
Ocr.Configuration.TesseractVersion = TesseractVersion.Tesseract5;
using (var Input = new OcrInput())
{
Input.AddImage(@"Demo.png");
var Result = Ocr.Read(Input);
Console.WriteLine(Result.Text);
Console.ReadKey();
}
var Ocr = new IronTesseract(); // nothing to configure
Ocr.Language = OcrLanguage.EnglishBest;
Ocr.Configuration.TesseractVersion = TesseractVersion.Tesseract5;
using (var Input = new OcrInput())
{
Input.AddImage(@"Demo.png");
var Result = Ocr.Read(Input);
Console.WriteLine(Result.Text);
Console.ReadKey();
}
Dim Ocr = New IronTesseract() ' nothing to configure
Ocr.Language = OcrLanguage.EnglishBest
Ocr.Configuration.TesseractVersion = TesseractVersion.Tesseract5
Using Input = New OcrInput()
Input.AddImage("Demo.png")
Dim Result = Ocr.Read(Input)
Console.WriteLine(Result.Text)
Console.ReadKey()
End Using
We can extract data from the image with the highest OCR accuracy by using the code mentioned above. Additionally, IronOCR facilitates the conversion of text extracted from handwritten documents into editable file formats, including Word. The scanned document can also be turned into a searchable PDF by us. With IronOCR, the outcome can be stored in various OCR output formats. To learn more about the code refer here.
Source Image:
Result:
In conclusion, Tesseract and Microsoft OCR, each with unique advantages and disadvantages, provide strong OCR capabilities for C# developers. Because Tesseract offers customization and flexibility, it is a good choice for applications that require a great deal of fine-tuning. However, Microsoft OCR is the best option for C# applications that need sophisticated text recognition capabilities because of its high accuracy, scalability, and seamless connection with Azure services. For their C# projects, developers should weigh their individual needs, modification requirements, and financial limits before deciding between Tesseract and Microsoft OCR.
Lastly, IronOCR is a remarkable OCR solution that offers outstanding integration, flexibility, and accuracy. Because of its unparalleled accuracy, advanced algorithms, and capacity to identify a wide range of document types, including handwritten ones, IronOCR is the greatest OCR solution currently on the market. Because IronOCR integrates smoothly across numerous documents and common computer languages, it ensures developer accessibility while maintaining an intuitive interface.
You can try the affordable development edition of IronOCR for free, and if you buy the IronOCR package, you'll get a lifetime license. With a starting price of $749, the IronOCR bundle is an excellent value as it offers a single price for several devices. To learn more about the cost, visit the IronOCR website. Click this link to learn more about Iron Software products.
9 .NET API products for your office documents