Published February 27, 2023
How to OCR License Plate in C# (Tutorial)
In this tutorial, we will learn about programmatic license plate recognition. We will take some sample license plate images and extract the license plate number. We will develop a C# and .NET program to perform automatic license plate recognition. This tutorial is simple and easy so is perfect even for a beginner C# programmer.
You may wonder why we might need to determine the license plate number from an image. The answer is straightforward: maybe you are developing an application that takes data from CCTV videos, and your program needs to read the license plate characters in order to identify the vehicle.
We need an efficient Optical Character Recognition (OCR) engine that can process the image and accurately return the license plate number, irrespective of the language or characters of the plate.
There are many libraries available to perform OCR. Some of them are paid, some of them are difficult to use, and some of them are not efficient or accurate. It can be very difficult to find a library that is free, efficient, easy to use, and provides accurate results. I found and used IronOCR; it's free for development, provides a 1 month free trial for commercial use, is easy to use, is efficient, provides multi-threading, supports 150+ languages, and on top of all this also provides better accuracy. It will perform all tasks from license plate detection to getting license plate numbers.
How to Use License Plate Recognition in C#
- Install C# library to use license plate recognition
- Import the license plate image to a new OcrInput instance
- Apply image filters to improve recognition in C#
- Improve recognition speed by specifying the license plate region in the image
- Print out the extracted license plate data
IronOCR
IronOCR is a library developed and maintained by Iron Software that helps C# Software Engineers to perform OCR, Barcode Scanning, and Text Extraction in .NET projects.
Features of IronOCR
- Reading text from many formats such as images (jpg, png, gif, tiff, BMP), streams, and PDFs
- Correcting low-quality scans and photos with a plethora of filters such as
Deskew
,Denoise
,Binarize
,Enhance Resolution
,Dilate
, and many more - Reading barcodes from over 20 barcode formats and QR code support
- Utilizing the latest build of Tesseract OCR, tuned for performance
- Exporting searchable PDFs, HTML, and image content text.
Let's develop a demo application to read license plate numbers.
Create a Visual Studio Project
The first step is to create a Visual Studio project.
Open Visual Studio. Click on Create New Project, and select Project Template (I have selected the Console Application template for this demo application, but you can select any as per your requirement or preference). Click on the Next button, and name the project (I have named it "License plate OCR", but you can name it anything). Click on the Next button, and select your target framework. Finally, click on the Create button to create the project. The project will be created as shown below.

Creating a Visual Studio Project for our License Plate OCR Project
Now, we need to install the IronOCR library to use it in our project. The easiest way is to install it via the NuGet Package Manager.
Install IronOCR NuGet Package
Click on Tools from the top menu bar, and select NuGet Package Manager > Manage NuGet Packages for Solution, as shown below.

Locating the NuGet Package Manager UI in Visual Studio
The following window will appear.

The NuGet Package Manager UI in Visual Studio
Click on Browse, and search for IronOCR. Select the IronOCR package and click on the Install button, as shown below.

Locate the IronOCR package in the Package Manager UI and click the Install button to add it to the project
The IronOCR Library will be installed and ready to use.
Read License Plates using Optical Character Recognition
Let's write a program to read the license plate. IronOCR is a tesseract OCR Engine that is used to extract text from an image, so if we need to implement computer vision to detect vehicles, we may need to use some other machine-learning libraries. IronOCR supports OpenCV, which is an open-source and market-leading detection model. IronOCR can be used with OpenCV to perform object detection such as car detection or detect license plates.
We will read the following number plate:

Image of a License Plate with license plate numbers clearly visible
Now, we'll write the code.
Add the following namespace:
using IronOcr;
using IronOcr;
Imports IronOcr
Then add the following code:
var Ocr = new IronTesseract();
using (var Input = new OcrInput(@"D:\Liscence Plate\plate3.jpg"))
{
Input.DeNoise(); // fixes digital noise and poor scanning
Input.ToGrayScale();
var Result = Ocr.Read(Input);
Console.WriteLine(Result.Text);
}
var Ocr = new IronTesseract();
using (var Input = new OcrInput(@"D:\Liscence Plate\plate3.jpg"))
{
Input.DeNoise(); // fixes digital noise and poor scanning
Input.ToGrayScale();
var Result = Ocr.Read(Input);
Console.WriteLine(Result.Text);
}
Dim Ocr = New IronTesseract()
Using Input = New OcrInput("D:\Liscence Plate\plate3.jpg")
Input.DeNoise() ' fixes digital noise and poor scanning
Input.ToGrayScale()
Dim Result = Ocr.Read(Input)
Console.WriteLine(Result.Text)
End Using
This performs the following:
- Initializes the
IronTesseract
object with default settings. - Creates a new
OCRInput
object populated with an input image file. - Invokes
DeNoise
, which removes digital noise. This filter should only be used where noise is expected; in our case, CCTV Videos or pictures are often full of noise. - Invokes the
ToGrayScale
filter, which turns every pixel into a shade of grey (this may improve speed). - Reads text from an
OCRInput
object via theRead
method, which returns anOCRResult
object.OCRInput
is the preferred input type because it allows for OCR of multi-paged documents, and allows images to be enhanced prior to reading to obtain faster, more accurate results. Result.Text
returns the entire content extracted from the license plate.
We can see that the correct license number is extracted from the detected license plate.

IronOCR correctly detects and extracts the numbers from the license plate image
Let's suppose, we don't have separate license plates, we have a picture of the complete car. Now, we need to scan the area of the Number plate and perform text recognition.
Scanning License Plate Numbers from a Car
We can use a System.Drawing.Rectangle
to specify a region in which we will read a license plate. The unit of measurement is always pixels.
We will use the following example image file.

Full, rearview image of a car with visible license plate
We will see that this provides speed improvements as well as avoiding reading unnecessary text.
var Ocr = new IronTesseract();
using (var Input = new OcrInput())
{
// a 41% improvement on speed
var ContentArea = new CropRectangle(x: 365, y: 240, height: 80, width: 29);
Input.AddImage(@"D:\Liscence Plate\plate1.jpg", ContentArea);
var Result = Ocr.Read(Input);
Console.WriteLine(Result.Text);
}
var Ocr = new IronTesseract();
using (var Input = new OcrInput())
{
// a 41% improvement on speed
var ContentArea = new CropRectangle(x: 365, y: 240, height: 80, width: 29);
Input.AddImage(@"D:\Liscence Plate\plate1.jpg", ContentArea);
var Result = Ocr.Read(Input);
Console.WriteLine(Result.Text);
}
Dim Ocr = New IronTesseract()
Using Input = New OcrInput()
' a 41% improvement on speed
Dim ContentArea = New CropRectangle(x:= 365, y:= 240, height:= 80, width:= 29)
Input.AddImage("D:\Liscence Plate\plate1.jpg", ContentArea)
Dim Result = Ocr.Read(Input)
Console.WriteLine(Result.Text)
End Using
This yields a 41% speed increase - and allows us to be specific. We specify the starting coordinates for the region (x and y) and the width and height of the detection region.
ContentAreas (OCR cropping) is also supported when reading PDFs.
Automatic License Plate Recognition
IronOCR utilizes OpenCV to use Computer Vision to detect areas where text exists in an image. It performs image processing techniques and uses a detection model for detecting license plates. The use of computer vision in IronOCR will determine where text regions exist and then use Tesseract to attempt to read those regions.
We need to install IronOcr.ComputerVision.Windows
for using license plate detection model.
Use the following command in Package Manager Console.
PM> Install-Package IronOcr.ComputerVision.Windows
This will provide the necessary assemblies to use IronOCR Computer Vision with our model file.
The following sample code will automatically detect the license plate from the car.
var ocr = new IronTesseract();
using (var input = new OcrInput(@"D:\Liscence Plate\plate1.jpg"))
{
input.FindTextRegion();
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);
}
var ocr = new IronTesseract();
using (var input = new OcrInput(@"D:\Liscence Plate\plate1.jpg"))
{
input.FindTextRegion();
OcrResult result = ocr.Read(input);
Console.WriteLine(result.Text);
}
Dim ocr = New IronTesseract()
Using input = New OcrInput("D:\Liscence Plate\plate1.jpg")
input.FindTextRegion()
Dim result As OcrResult = ocr.Read(input)
Console.WriteLine(result.Text)
End Using
Usage of FindTextRegion
will use Computer Vision to detect regions that contain license plates on every image of an OcrInput
object.
Summary
In this tutorial, we have learned to use IronOCR and developed a straightforward program to read a car's license plate. We have seen that IronOCR enables us to read text from blurred or low-resolution images, is efficient, provides high accuracy, supports 127+ languages with full accuracy, is free for development, and has no restriction on production.
In summary, IronOCR provides:
- OCR for C# to scan and read images and PDFs
- .NET OCR library with 127+ global language packs
- Output as text, structured data, or searchable PDFs
- Supports .NET 6, 5, Core, Standard, Framework
IronOCR is part of the Iron Suite. This suite contains other very useful libraries such as IronPDF for reading and writing PDFs, IronXL for manipulating Excel files, and IronWebScrapper for extracting data from websites. You can purchase Iron Suite for the cost of two library licenses.