IronOCR is a C# software library allowing .NET platform software developers to recognize and read text from images and PDF documents. It converts images to text. As a bonus, Iron OCR can also read barcodes and QR codes and return them to the developer.
The first thing we have to do is install our OCR library into a Visual Studio project. To do this, we can choose one of two approaches:
PM > Install-Package IronOcr
Iron OCR is an easy-to-install, complete and well-documented .NET software library. Iron OCR shines when working with real world images and imperfect documents such as photographs, or scans of low resolution which may have digital noise or imperfections. Other free OCR libraries for the .NET platform such as Tesseract do not perform so well on these real world use cases.
Iron OCR provides an excellent balance of performance against accuracy for image-to-text conversion in .NET.
The Iron OCR Automated OCR class is the easiest way for developers to get started with optical character recognition in .NET. The Auto OCR class automatically detects image properties and adjusts for them, making best guesses about the most appropriate settings to read that document. It automatically corrects for digital noise, rotation, perspective, and even low-resolution documents.
The code sample below shows how easy it is to read text from an image using C# or VB .NET.
The same approach can similarly be used to extract text from a PDF document.
The Iron OCR Advanced OCR class gives the developer granular control over the OCR operation, allowing them to achieve the highest degree of accuracy for very specific use cases.
Iron Advanced OCR can also be used to extract text from pages or entire PDF documents.
Advanced OCR settings include:
CleanBackgroundNoise. This is a setting which is somewhat time-consuming; however, it allows the library to automatically clean digital noise, paper crumples, and other imperfections within a digital image which would otherwise render it incapable of being read by other OCR libraries.
EnhanceContrast is a setting which causes Iron OCR to automatically increase the contrast of text against the background of an image, increasing the accuracy of OCR and generally increasing performance and the speed of OCR.
EnhanceResolution is a setting which will automatically detect low-resolution images (which are under 275 dpi) and automatically upscale the image and then sharpen all of the text so it can be read perfectly by an OCR library. Although this operation is in itself time-consuming, it generally reduces the overall time for an OCR operation on an image.
Language Iron OCR supports 22 international language packs, and the language setting can be used to select one or more multiple languages to be applied for an OCR operation.
Strategy Iron OCR supports two strategies. We may choose to either go for a fast and less accurate scan of a document, or use an advanced strategy which uses some artificial intelligence models to automatically improve the accuracy of OCR text by looking at the statistical relationship of words to one another in a sentence.
ColorSpace is a setting whereby we can choose to OCR in grayscale or color. Generally, grayscale is the best option. However, sometimes when there are texts or backgrounds of similar hue but very different color, a full-color color space will provide better results.
DetectWhiteTextOnDarkBackgrounds. Generally, all OCR libraries expect to see black text on white backgrounds. This setting allows Iron OCR to automatically detect negatives, or dark pages with white text, and read them.
InputImageType. This setting allows the developer to guide the OCR library as to whether it is looking at a full document or a snippet, such as a screenshot.
RotateAndStraighten is an advanced setting which allows Iron OCR the unique ability to read documents which are not only rotated, but perhaps containing perspective, such as photographs of text documents.
ReadBarcodes is a useful feature which allows Iron OCR to automatically read barcodes and QR codes on pages as it also reads text, without adding a large additional time burden.
ColorDepth. This setting determines how many bits per pixel the OCR library will use to determine the depth of a color. A higher color depth may increase OCR quality, but will also increase the time required for the OCR operation to complete.
Iron OCR has support for 22 international languages. By default, only English is installed. You can install additional languages via NuGet or by downloading DLLs from our Language Packs page.
Likewise for AdvancedOcr:
A bonus feature of Iron OCR is it can read barcodes and QR codes from documents while it is scanning for text. Instances of the OcrResult.OcrBarcode Class give the developer detailed information about each scanned barcode.
All of Iron OCR’s scanning and reading methods provide the ability to add a crop region, or to specify exactly which part of a page or pages we wish to read text from. This is very useful when we are looking at standardized forms and can save an awful lot of time and improve efficiency.
To use crop regions, we will need to add a system reference to the System.Drawing DLL so that we can use the System.Drawing.Rectangle object.
Iron OCR returns an OCR result object for each OCR operation. Generally, developers only use the text property of this object to get the text scanned from the image. However, the OCR results object is much more advanced than this.
In the code sample below, we can see how we may iterate an OCR results object to look at the paragraphs, lines, words and characters of text which have been read during OCR, inspect them for statistical accuracy, and even look at them as images on a page by page basis.
Reading (the action of recognizing text from a visual image) is a human art which computers are only just learning to achieve. All OCR is inherently slow, and even on a modern i7 or XEON based server, we can expect OCR to achieve only human reading speeds. This can be a surprise to developers at first, but it’s perfectly normal.
The higher the quality of the input document, the faster the results will come out. It can be counterintuitive that larger documents with higher dpis (of an optimum range from perhaps 250 to 300 dpi) will actually scan faster than smaller image formats.
We will note that wherever possible, Iron OCR will use multithreading to speed up OCR operations on a page by page basis. This is particularly useful when batch processing images or reading multi-page PDF documents.
To learn more about OCR in C#, VB, F#, or any other .NET language, please read our community tutorials, which give real world examples of how Iron OCR can be used and may show the nuances of how to get the best out of this library.
A full object reference for .NET developers is also available.
Talk directly with our development team
Clear online manuals in plain English.
Free development license. Commercial from $399.