Scan, read, and extract MRZ data from passports
This guide demonstrates how to extract machine-readable zone (MRZ) data from passports using Nutrient .NET SDK. The MRZ, typically found at the bottom of personal identification documents, is readable via optical character recognition (OCR). Nutrient .NET SDK’s advanced OCR engine enables recognition of MRZ data in machine-readable travel documents (MRTD), including passports, visas, and ID cards.
Extract MRZ information
To extract MRZ information from a passport, follow the steps below:
- Create a
GdPictureImagingobject and aGdPictureOCRobject. - Select the image by passing its path to the
CreateGdPictureImageFromFilemethod of theGdPictureImagingobject. - Set the image with the
SetImagemethod of theGdPictureOCRobject. - Run the OCR process by passing
OCRSpecialContext.MRZto theRunOCRmethod of theGdPictureOCRobject. - Get the result of the OCR process as text with the
GetOCRResultTextmethod of theGdPictureOCRobject. - Write the output to the console.
- Release unnecessary resources.
The following example extracts MRZ information from a passport:
using GdPictureImaging gdpictureImaging = new GdPictureImaging();using GdPictureOCR gdpictureOCR = new GdPictureOCR();// Select the image to process.int imageId = gdpictureImaging.CreateGdPictureImageFromFile(@"C:\temp\source.png");// Set the image.gdpictureOCR.SetImage(imageId);// Run the OCR process.string resultId = gdpictureOCR.RunOCR(OCRSpecialContext.MRZ);// Get the result of the OCR process as text.string mrzData = gdpictureOCR.GetOCRResultText(resultId);// Write the output to the console.Console.WriteLine($"MRZ information: {mrzData}");// Release unnecessary resources.gdpictureImaging.ReleaseGdPictureImage(imageId);gdpictureOCR.ReleaseOCRResults();Using gdpictureImaging As GdPictureImaging = New GdPictureImaging()Using gdpictureOCR As GdPictureOCR = New GdPictureOCR() ' Select the image to process. Dim imageId As Integer = gdpictureImaging.CreateGdPictureImageFromFile("C:\temp\source.png") ' Set the image. gdpictureOCR.SetImage(imageId) ' Run the OCR process. Dim resultId As String = gdpictureOCR.RunOCR(OCRSpecialContext.MRZ) ' Get the result of the OCR process as text. Dim mrzData As String = gdpictureOCR.GetOCRResultText(resultId) ' Write the output to the console. Console.WriteLine($"MRZ information: {mrzData}") ' Release unnecessary resources. gdpictureImaging.ReleaseGdPictureImage(imageId) gdpictureOCR.ReleaseOCRResults()End UsingEnd UsingUsed methods and properties
Related topics