Read Passport
This code example demonstrates how to use the IronTesseract OCR engine to extract and process passport information from an image.
The IronTesseract OCR engine is instantiated. An OcrInput
object is created to load the image containing the passport ("passport.jpg") using the LoadImage
method. The ReadPassport
method is used to process the image and extract passport information, returning an OcrPassportResult
object that contains details like the given names, surname, country, passport number, date of birth, and date of expiry. The extracted passport information is then outputted to the console:
- The given names are accessed through
result.PassportInfo.GivenNames
. - The country is retrieved using
result.PassportInfo.Country
. - The passport number is available via
result.PassportInfo.PassportNumber
. - The surname is accessed with
result.PassportInfo.Surname
. - The date of birth is printed using
result.PassportInfo.DateOfBirth
. - The expiry date is outputted with
result.PassportInfo.DateOfExpiry
.
This method is useful for automating the extraction of key passport data for processing or verification purposes.
using IronOcr;
class Program
{
static void Main(string[] args)
{
// Initialize the IronTesseract engine
var Ocr = new IronTesseract();
// Create an OCR input object and load the image
using (var Input = new OcrInput())
{
// Load the passport image for processing
Input.AddImage("passport.jpg");
// Process the image and extract passport information
OcrResult Result = Ocr.ReadPassport(Input);
// Access and print extracted passport information
Console.WriteLine("Given Names: " + Result.PassportInfo.GivenNames);
Console.WriteLine("Country: " + Result.PassportInfo.Country);
Console.WriteLine("Passport Number: " + Result.PassportInfo.PassportNumber);
Console.WriteLine("Surname: " + Result.PassportInfo.Surname);
Console.WriteLine("Date of Birth: " + Result.PassportInfo.DateOfBirth.ToShortDateString());
Console.WriteLine("Date of Expiry: " + Result.PassportInfo.DateOfExpiry.ToShortDateString());
}
}
}
using IronOcr;
class Program
{
static void Main(string[] args)
{
// Initialize the IronTesseract engine
var Ocr = new IronTesseract();
// Create an OCR input object and load the image
using (var Input = new OcrInput())
{
// Load the passport image for processing
Input.AddImage("passport.jpg");
// Process the image and extract passport information
OcrResult Result = Ocr.ReadPassport(Input);
// Access and print extracted passport information
Console.WriteLine("Given Names: " + Result.PassportInfo.GivenNames);
Console.WriteLine("Country: " + Result.PassportInfo.Country);
Console.WriteLine("Passport Number: " + Result.PassportInfo.PassportNumber);
Console.WriteLine("Surname: " + Result.PassportInfo.Surname);
Console.WriteLine("Date of Birth: " + Result.PassportInfo.DateOfBirth.ToShortDateString());
Console.WriteLine("Date of Expiry: " + Result.PassportInfo.DateOfExpiry.ToShortDateString());
}
}
}