Test in production without watermarks.
Works wherever you need it to.
Get 30 days of fully functional product.
Have it up and running in minutes.
Full access to our support engineering team during your product trial
OCR stands for Optical Character Recognition. It provides the facility to convert an image file to machine-encoded text. The scanned documents are always saved as an image file by the computer. The data in these image files cannot be searched, edited, or saved in text format using a normal text editor or even using a word processing application. OCR processing helps convert these images to machine-readable text for further processing by its users.
In this modern age, the scanned documents shared over the internet are in digital format, mostly in the form of PDFs or images. There are a bunch of online resources available which convert the image to text. However, most businesses require this functionality in their software applications. Keeping this in mind, there are many libraries which provide OCR processing technology to be embedded in software applications.
In this article, we are going to discuss two of the most popular OCR libraries for C#. These are:
IronOCR for .NET is a C# library to scan, search, and read images & PDFs. It takes an image or PDF file as input and uses the latest Tesseract 5 custom build .NET OCR engine to output text, structured data, or searchable PDF documents. Tesseract is available in 125+ languages, along with cross-platform support in .NET Core, and .NET Standard, from 2.0 up to 7.
IronOCR is a user-friendly API which allows C# developers to convert images to text automatically, using the IronTesseract
class and an API key. It prioritizes speed, accuracy, and ease of use. It also aids the Computer Vision API to find text with a trained set of models.
Another powerful feature of IronOCR is that it can scan barcodes & QR codes from all image files and read their text. Other important features of IronOCR are given below.
System.Drawing Objects
, Streams, PDF documents (optimized target DPI)Now, let's have a look at Google Cloud Vision API.
Google Cloud Vision API is a Google Cloud OCR client library which supports the C# language. It allows C# developers to easily integrate Computer Vision detection features into software applications. It performs OCR and detects text from image files, image labels, face detection, and landmark detection.
Google Cloud Vision API uses REST and RPC APIs to provide a powerful pretrained ML (machine learning) model. With Cloud Vision API, you can quickly classify images into millions of already predefined categories. It can also detect objects and read text from printed documents and handwritten text.
The rest of the article goes as follows:
In this tutorial, we are going to use Visual Studio 2022, the latest version. So, I assume you have already downloaded and installed it for C#. If not, you can download it from the Visual Studio website.
Now, we need to create a Console project to get started with both libraries. Follow the steps to create a project:
Click on Create a new Project.
Select C# Console Application from the given options.
Click Next.
From additional information, select .NET 6.0 Framework as it is the most stable version.
Next, we will install the libraries in our project for comparison.
There are multiple ways to install the IronOCR library. Let's have a look at them one by one.
NuGet is the package manager for downloading and installing dependencies in your project. Its packages contain the compiled code (DLL) and the manifest file. Access it using the following method:
Click Manage NuGet Packages for Solution
Click Manage NuGet Packages
Now, the NuGet Package Manager window will open. Browse for IronOCR and click Install.
It can be downloaded directly from the NuGet official website. Follow the given steps:
Simply visit the Iron Software website and navigate to the IronOCR for .NET webpage. Scroll to the bottom and click Download DLL or Download Windows Installer.
A Zip file will be downloaded. Extract it and add it to your project file or run the Windows Installer. Follow the below steps to add it to your project.
Install-Package IronOcr
This will automatically download and install IronOCR in your project.
Now, we are ready to use IronOCR in our project.
There is only one namespace required, and it needs to be added on top of the source code file where we need to access its functions.
using IronOcr;
using IronOcr;
Now, let's install Google Vision OCR.
To be able to use the Vision API in your C# project, you must have the following prerequisites fulfilled:
You can have a detailed look at the setup and requirements of using Google Cloud Vision from the official documentation here.
Now, to install the Google Cloud client library for performing OCR processing in Visual Studio, we need to use the NuGet Package Manager.
Access it using the following method:
Click Manage NuGet Packages for Solution
Click Manage NuGet Packages
Now, the NuGet Package Manager window will open. Browse for Google Cloud Vision OCR and click Install.
Include the following namespace to use Google OCR Vision API:
using Google.Cloud.Vision.V1;
using Google.Cloud.Vision.V1;
Also, set the environment variable with the key credentials downloaded in JSON file format.
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", "key.json");
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", "key.json");
Now, everything is set up and ready to use.
Reading data from images is a tedious task. Image resolution and quality play an important role while extracting content. Both libraries provide Optical Character Recognition (OCR) functionality to extract text from images.
IronOCR makes it very easy for developers to read the contents of an image file with its powerful IronTesseract
class. Here we will use a PNG image to read text from an image file and the code is as follows:
var ocr = new IronTesseract();
using (var input = new OcrInput())
{
// Add the image to be processed
input.AddImage("test-files/employmentapp.png");
// Process the image
var result = ocr.Read(input);
// Output the extracted text
Console.WriteLine(result.Text);
}
var ocr = new IronTesseract();
using (var input = new OcrInput())
{
// Add the image to be processed
input.AddImage("test-files/employmentapp.png");
// Process the image
var result = ocr.Read(input);
// Output the extracted text
Console.WriteLine(result.Text);
}
The output of IronOCR matches the original image given to it. The code is clean and easy to understand without any technicalities.
Google Cloud Vision OCR also converts the image to text with different fonts. First, we need to create a client using the credentials file. Then using this client object, we can call the DetectText
method to get a response in form of annotation. The code is given as follows:
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", "key.json");
var client = ImageAnnotatorClient.Create();
var image = Google.Cloud.Vision.V1.Image.FromFile("test-files/employmentapp.png");
var response = client.DetectText(image);
foreach (var annotation in response)
{
if (annotation.Description != null)
{
Console.WriteLine(annotation.Description);
}
}
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", "key.json");
var client = ImageAnnotatorClient.Create();
var image = Google.Cloud.Vision.V1.Image.FromFile("test-files/employmentapp.png");
var response = client.DetectText(image);
foreach (var annotation in response)
{
if (annotation.Description != null)
{
Console.WriteLine(annotation.Description);
}
}
The same image is given as input in order to compare the output of both libraries.
From the above output, you can clearly see that IronOCR preserves the image output formats. Although Google OCR has given accurate output text, the formatting of the table is not preserved. IronOCR has preserved the formatting of the table exactly as in the given image.
IronOCR provides a unique and useful feature while reading images, i.e., it can read barcodes and QR Codes. It can detect barcodes and display their value with ease. First, set the ReadBarCodes
configuration to true, and then iterate through each of the barcodes in the OCR results. The code for reading barcodes is given below:
var ocr = new IronTesseract();
ocr.Configuration.ReadBarCodes = true;
using (var input = new OcrInput())
{
// Add the image to be processed
input.AddImage("test-files/Barcode.png");
// Process the image
var result = ocr.Read(input);
// Iterate and output barcode values
foreach (var barcode in result.Barcodes)
{
Console.WriteLine(barcode.Value);
}
}
var ocr = new IronTesseract();
ocr.Configuration.ReadBarCodes = true;
using (var input = new OcrInput())
{
// Add the image to be processed
input.AddImage("test-files/Barcode.png");
// Process the image
var result = ocr.Read(input);
// Iterate and output barcode values
foreach (var barcode in result.Barcodes)
{
Console.WriteLine(barcode.Value);
}
}
All the three barcodes in the input are read successfully, and their hidden text is displayed.
Google Vision API does not allow this functionality yet. Reading barcodes can be handy in software applications. However, Google OCR allows you to get text from a scanned document as an image file. Code for label detection is as follows:
var client = ImageAnnotatorClient.Create();
var image = Google.Cloud.Vision.V1.Image.FromUri("gs://cloud-samples-data/vision/using_curl/shanghai.jpeg");
var labels = client.DetectLabels(image);
Console.WriteLine("Labels (and confidence score):");
Console.WriteLine(new String('=', 30));
foreach (var label in labels)
{
Console.WriteLine($"{label.Description} ({(int)(label.Score * 100)}%)");
}
var client = ImageAnnotatorClient.Create();
var image = Google.Cloud.Vision.V1.Image.FromUri("gs://cloud-samples-data/vision/using_curl/shanghai.jpeg");
var labels = client.DetectLabels(image);
Console.WriteLine("Labels (and confidence score):");
Console.WriteLine(new String('=', 30));
foreach (var label in labels)
{
Console.WriteLine($"{label.Description} ({(int)(label.Score * 100)}%)");
}
Reading PDF files is as easy as reading image files in IronOCR. You only need to change the AddImage
method to AddPdf
in the image reading code. The code goes as follows:
var ocr = new IronTesseract();
using (var input = new OcrInput())
{
// Add the PDF to be processed
input.AddPdf("test-files/example.PDF");
// Process the PDF
var result = ocr.Read(input);
// Output the extracted text
Console.WriteLine(result.Text);
}
var ocr = new IronTesseract();
using (var input = new OcrInput())
{
// Add the PDF to be processed
input.AddPdf("test-files/example.PDF");
// Process the PDF
var result = ocr.Read(input);
// Output the extracted text
Console.WriteLine(result.Text);
}
The extracted text is in the same formatting as the PDF file.
Google OCR also provides the facility to extract text from PDF/TIFF documents. However, it only detects text if the file is in Google Cloud Storage. For this, you need to create a Google Storage bucket. The code for C# is not straightforward and quite lengthy to implement here. There are no samples available for C# to detect texts in files. You can look at Java code as a reference to try.
IronOCR is free for development purposes, but it needs to be licensed for commercial use. It also provides a free trial to test all its potential for your needs. The Lite package starts from a certain amount with a free trial. IronOCR provides 1 year of product support and updates for free and then a year after it costs $399. All licenses are perpetual, meaning only a one-time purchase and no hidden charges. You can also choose royalty-free redistribution coverage for SaaS and OEM products with just a $1999 single-time purchase. For more info on license packages and pricing plans, please visit here.
Google Cloud Vision pricing plans are based on the number of operations performed by the application on an image. For files like PDF which have multiple pages, each page is treated as an image. Moreover, each feature applied to an image is a separate billable unit. For example, if you apply text detection and label detection to the same image, each feature will be charged separately. The pricing plans are given below, and for more info, please visit this link.
IronOCR provides C# developers the most advanced Tesseract API we know of, on any platform. IronOCR can be deployed on Windows, Linux, Mac, Azure, AWS, Lambda, and supports .NET Framework projects as well as .NET Standard and .NET Core projects. We can also read barcodes in OCR scans, and even export our OCR as HTML and searchable PDFs.
Google Cloud Vision API is an advanced AI built API. It provides a variety of image analyzing features which can be very helpful in building ML applications. It allows developers to directly communicate with the Google Cloud using an API key, which means there is no need to store files locally.
IronOCR licenses are user-based, which means you should always purchase a license based on the number of developers who will use the product. Google Cloud Vision licenses are based on the number of pictures to extract information from and analyze the data. The licenses are on a monthly basis, and the prices become very high for a large number of images as compared to IronOCR licenses. Moreover, the IronOCR license is a one-time purchase and it can be used for a lifetime, and it supports OEM and SaaS distribution.
In the overall conclusion, both libraries possess machine learning capabilities. IronOCR has a slight advantage over Google OCR as it is specifically built for C# .NET framework which is fast and time-saving. It provides all features with very few lines of code, lifting the burden from developers to write long lengthy codes. It is built on the most popular Tesseract 5 API which makes it easy to integrate and analyze images and other file formats with accurate output. On the other hand, Google Vision OCR is built on AI and more focused on Java, Python, and REST and can only run when connected to Google Cloud. This can be time-consuming as the response comes from the server side. You can choose the library according to your specific needs.
Now, you can get 5 Iron products for the price of 2. The following tools are included in the Iron Suite:
Visit this link to explore more.
You can download IronOCR from here.
OCR stands for Optical Character Recognition. It is a technology used to convert different types of documents, such as scanned paper documents, PDF files, or images captured by a digital camera, into editable and searchable data.
IronOCR offers features like reading text and barcodes from multiple languages, specialist document reading, support for various image and document formats, and image correction filters. It also emphasizes fast and high-quality performance.
Google Cloud Vision OCR uses a powerful pretrained ML model that allows for image text detection, document text detection, and more. It is highly integrated with Google Cloud services. IronOCR, on the other hand, is tailored for C# .NET applications and can function offline, offering features like barcode and QR code reading.
Yes, IronOCR can read barcodes and QR codes from image files, making it a versatile choice for applications that need to handle various types of data extraction.
Yes, IronOCR offers a free trial that allows developers to test its full capabilities before committing to a purchase.
IronOCR has a one-time purchase model with perpetual licenses, while Google Cloud Vision charges based on the number of operations performed, which can become costly with high usage.
Google Cloud Vision API supports multiple programming languages, including C#, Java, Python, and others, and requires an internet connection to function as it is cloud-based.
To use Google Cloud Vision OCR in a C# project, you need to create a Google Account, enable billing and the Vision API in Google Cloud Console, create a Service Account, and download the key credentials in JSON format.
Yes, IronOCR supports over 125 languages, including custom language support, making it highly adaptable for international applications.
IronOCR can be deployed on various platforms including Windows, Linux, Mac, Azure, AWS, and Lambda, and supports .NET Framework projects as well as .NET Standard and .NET Core projects.