Recognize MRZ characters from image in .NET

Blog category: OCR.NET

February 17, 2022

VintaSoft Imaging .NET SDK with VintaSoft OCR .NET Plug-in allows to recognize text from images using Tesseract OCR engine. A lot of dictionaries created for Tesseract OCR engine provide the ability to run the text recognition in more than 100 languages.

Few authors found in Internet suggest their free dictionaries for recognition of MRZ symbols (machine readable zones) using Tesseract OCR engine.
We have tested some of them and made sure that the dictionary "mrz.traineddata" provides good quality of MRZ symbols recognition.
The "mrz.traineddata" dictionary is offered under BSD-3 license, which allows the free use and redistribution of this file.
We make the "mrz.traineddata" dictionary available for download from our web site, also the dictionary can be downloaded from other Internet resources.

The "mrz.traineddata" dictionary is added into the list of supported dictionaries (MRZ item in Vintasoft.Imaging.Ocr.OcrLanguage enumeration) since version of VintaSoft OCR .NET Plug-in.

More detailed information about MRZ symbols you can read in Wikipedia:

Here is an image from Wikipedia, which represents a document with machine readable zone (MRZ):

Here is C# code, which demonstrates how to recognize MRZ symbols from image using Tesseract OCR engine:
/// <summary>
/// Recognizes MRZ characters from image using Tesseract OCR engine.
/// </summary>
/// <param name="filename">The name of file, which stores image with MRZ characters.</param>
public static void RecognizeMRZCharactersUsingTesseractOCR(string filename)
    // create an image collection
    using (Vintasoft.Imaging.ImageCollection images = 
        new Vintasoft.Imaging.ImageCollection())
        // add images from file to the image collection

        System.Console.WriteLine("Create Tesseract OCR engine...");
        // create the Tesseract OCR engine
        using (Vintasoft.Imaging.Ocr.Tesseract.TesseractOcr tesseractOcr = 
            new Vintasoft.Imaging.Ocr.Tesseract.TesseractOcr())
            System.Console.WriteLine("Initialize OCR engine...");
            // init the Tesseract OCR engine for recognition of MRZ characters (machine-readable zones)
            tesseractOcr.Init(new Vintasoft.Imaging.Ocr.OcrEngineSettings(Vintasoft.Imaging.Ocr.OcrLanguage.MRZ));

            // for each image in image collection
            foreach (Vintasoft.Imaging.VintasoftImage image in images)
                System.Console.WriteLine("Recognize the image...");
                // recognize text in image
                Vintasoft.Imaging.Ocr.Results.OcrPage ocrResult = tesseractOcr.Recognize(image);

                // output the recognized text

                System.Console.WriteLine("Page Text:");

            // shutdown the Tesseract OCR engine

        // free images