A Comparison Between Google OCR & IronOCR
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
- Google Cloud Vision OCR (Vision API)
IronOCR - C# Library
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.
Features
- International Languages: 125+ and custom languages support with High and Fast Quality performance
- Text and Barcode Reading: Read Text & Numbers from Multiple Languages at Once
- Specialist Documents: Specifically read text from Receipts, Cheques, Invoices
- Read from Many Formats: Images (PNG, JPG, GIF, TIFF, BMP),
System.Drawing Objects
, Streams, PDF documents (optimized target DPI) - Filters: Filter Wizard, Image Correction, Fix Image Orientation, Fix Image Colors
- Simple Data Output: .NET Text Strings, Barcode and QR Data, Images
Now, let's have a look at Google Cloud Vision API.
Google Cloud Vision OCR
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.
Features
- Image Text Detection: OCR an image for text recognition and convert it to machine language code
- Document Text Detection: OCR a file (PDF/TIFF), dense text
- Landmark Detection: Returns coordinates of detected objects
- Logo Detection: Returns a textual description
- Label Detection: Returns generalized labels for image
The rest of the article goes as follows:
- Creating a Visual Studio Project
- Installing IronOCR
- Installing Google OCR
- Image to Text
- Barcode and QR Code to Text
- PDF to Text
- Licensing
- Conclusion
1. Creating a Visual Studio Project
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:
- Open your Visual Studio 2022.
Click on Create a new Project.
Select C# Console Application from the given options.
- Configure your new project with a name and the location. E.g "OCRProject".
Click Next.
From additional information, select .NET 6.0 Framework as it is the most stable version.
- Now, click Create, and the project will be created in your specified location.
Next, we will install the libraries in our project for comparison.
2. Installing IronOCR
There are multiple ways to install the IronOCR library. Let's have a look at them one by one.
2.1. Using Visual Studio NuGet Package Manager
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 on the Tools tab
- Extend the NuGet Package Manager option
Click Manage NuGet Packages for Solution
- or, right-click Solution Explorer
Click Manage NuGet Packages
Now, the NuGet Package Manager window will open. Browse for IronOCR and click Install.
2.2. Download from NuGet Website
It can be downloaded directly from the NuGet official website. Follow the given steps:
- Click on the link to the NuGet website.
- Click the Download package option on the right-hand side of the page.
- Open the downloaded package, and it will start installing.
- Finally, reload the solution, and it's done.
2.3. Download using the IronOCR Webpage
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.
- Right-click the dependencies of the project in Visual Studio from the Solution Explorer.
- Then, select the option Add Project Reference.
- Browse to the downloaded DLL file location.
- Finally, click on OK to add the project reference.
2.4. Using the Command Prompt in Visual Studio
- Navigate to the Tools tab in Visual Studio.
- Extend the NuGet Package Manager option.
- Select Package Manager Console and type the following command:
Install-Package IronOcr
This will automatically download and install IronOCR in your project.
Now, we are ready to use IronOCR in our project.
2.5. Adding Necessary IronOCR Namespaces
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;
Imports IronOcr
Now, let's install Google Vision OCR.
3. Installing Google OCR
To be able to use the Vision API in your C# project, you must have the following prerequisites fulfilled:
- Create a Google Account
- Create a new project from Google Cloud Console
- Enable Billing
- Enable Vision API
- Create a Service Account and set the credentials
- Download the service account key credentials in JSON file format
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.
3.1. Using NuGet Package Manager
Access it using the following method:
- Click on the Tools tab
- Extend the NuGet Package Manager option
Click Manage NuGet Packages for Solution
- or, right-click Solution Explorer
Click Manage NuGet Packages
Now, the NuGet Package Manager window will open. Browse for Google Cloud Vision OCR and click Install.
3.2. Adding Google Vision API Namespace
Include the following namespace to use Google OCR Vision API:
using Google.Cloud.Vision.V1;
using Google.Cloud.Vision.V1;
Imports 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");
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", "key.json")
Now, everything is set up and ready to use.
4. Image to Text
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.
4.1. Using IronOCR
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);
}
Dim ocr = New IronTesseract()
Using input = New OcrInput()
' Add the image to be processed
input.AddImage("test-files/employmentapp.png")
' Process the image
Dim result = ocr.Read(input)
' Output the extracted text
Console.WriteLine(result.Text)
End Using
INPUT IMAGE
OUTPUT
The output of IronOCR matches the original image given to it. The code is clean and easy to understand without any technicalities.
4.2. Using Google OCR
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);
}
}
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", "key.json")
Dim client = ImageAnnotatorClient.Create()
Dim image = Google.Cloud.Vision.V1.Image.FromFile("test-files/employmentapp.png")
Dim response = client.DetectText(image)
For Each annotation In response
If annotation.Description IsNot Nothing Then
Console.WriteLine(annotation.Description)
End If
Next annotation
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.
5. Barcode and QR Code to Text
5.1. Using IronOCR
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);
}
}
Dim ocr = New IronTesseract()
ocr.Configuration.ReadBarCodes = True
Using input = New OcrInput()
' Add the image to be processed
input.AddImage("test-files/Barcode.png")
' Process the image
Dim result = ocr.Read(input)
' Iterate and output barcode values
For Each barcode In result.Barcodes
Console.WriteLine(barcode.Value)
Next barcode
End Using
INPUT IMAGE
OUTPUT
All the three barcodes in the input are read successfully, and their hidden text is displayed.
5.2. Using Google OCR
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)}%)");
}
Imports System
Dim client = ImageAnnotatorClient.Create()
Dim image = Google.Cloud.Vision.V1.Image.FromUri("gs://cloud-samples-data/vision/using_curl/shanghai.jpeg")
Dim labels = client.DetectLabels(image)
Console.WriteLine("Labels (and confidence score):")
Console.WriteLine(New String("="c, 30))
For Each label In labels
Console.WriteLine($"{label.Description} ({CInt(Math.Truncate(label.Score * 100))}%)")
Next label
OUTPUT
6. PDF to Text
6.1. Using IronOCR
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);
}
Dim ocr = New IronTesseract()
Using input = New OcrInput()
' Add the PDF to be processed
input.AddPdf("test-files/example.PDF")
' Process the PDF
Dim result = ocr.Read(input)
' Output the extracted text
Console.WriteLine(result.Text)
End Using
OUTPUT
The extracted text is in the same formatting as the PDF file.
6.2. Using Google OCR
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.
7. Licensing
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.
8. Conclusion
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:
- IronBarcode
- IronXL
- IronOCR
- IronPDF
- IronWebscraper
Visit this link to explore more.
You can download IronOCR from here.
Frequently Asked Questions
How can I convert images to text using C#?
You can use IronOCR which utilizes the Tesseract 5 engine to convert images into machine-readable text. It supports over 125 languages and is compatible with multiple platforms, making it an excellent choice for text extraction in C# applications.
What are the benefits of using IronOCR for barcode and QR code scanning?
IronOCR not only converts images and PDFs into text but also excels in barcode and QR code scanning. It provides quick and accurate data extraction, making it a versatile tool for applications needing comprehensive OCR capabilities.
How does IronOCR handle different languages?
IronOCR supports over 125 languages and offers custom language support. This extensive language compatibility allows it to be highly adaptable for international applications, ensuring text recognition across various languages.
What are the installation requirements for IronOCR in a C# project?
To install IronOCR in a C# project, you can use NuGet package manager in Visual Studio. Simply search for IronOCR in the NuGet Package Manager and install it to seamlessly integrate OCR functionalities into your application.
How does IronOCR's licensing model compare to cloud-based OCR services?
IronOCR offers a one-time purchase model with perpetual licenses, providing long-term value without recurring costs. In contrast, cloud-based OCR services like Google Cloud Vision typically use a pay-per-use pricing model, which can become expensive with high usage.
What platforms are supported by IronOCR?
IronOCR can be deployed on various platforms including Windows, Linux, Mac, Azure, AWS, and Lambda. It supports .NET Framework, .NET Standard, and .NET Core projects, offering versatility for different development environments.
Can IronOCR function offline?
Yes, IronOCR can function offline, which is a significant advantage over cloud-based solutions. This capability ensures that your OCR processing is not dependent on an internet connection, offering greater control and security.
How does IronOCR ensure accuracy and speed in OCR processing?
IronOCR utilizes advanced algorithms and the Tesseract 5 engine to provide fast and accurate OCR processing. Its image correction filters further enhance text recognition accuracy, making it a reliable choice for high-quality OCR tasks.