.NETで画像からMRZ文字を認識

ブログ カテゴリ: OCR.NET

2022/02/17

VintaSoft Imaging .NET SDKVintaSoft OCR .NET Plug-in を使用すると、Tesseract OCR エンジンを使用して画像からテキストを認識できます。Tesseract OCR エンジン用に作成された多くの辞書は、100 を超える言語でテキスト認識を実行する機能を提供します。

インターネット上で、Tesseract OCRエンジンを使用してMRZシンボル(機械可読領域)を認識するための無料辞書を提案している人はほとんどいません。
いくつかをテストした結果、辞書「mrz.traineddata」が優れた品質のMRZシンボル認識を提供することがわかりました。
「mrz.traineddata」辞書はBSD-3ライセンスに基づいて提供されており、このファイルの自由な使用と再配布が許可されています。
「mrz.traineddata」辞書は 弊社 Web サイト からダウンロードできます。また、この辞書は他のインターネット リソースからもダウンロードできます。

VintaSoft OCR .NET Plug-in バージョン 11.0.5.1 以降、サポートされる辞書のリスト (Vintasoft.Imaging.Ocr.OcrLanguage 列挙の MRZ 項目) に「mrz.traineddata」辞書が追加されました。

MRZ シンボルの詳細については、Wikipedia: https://en.wikipedia.org/wiki/Machine-readable_passport をご覧ください。

これは、機械可読領域(MRZ)を含む文書を表すWikipediaの画像です。



これは、Tesseract OCRエンジンを使用して画像からMRZシンボルを認識する方法を示すC#コードです。
/// <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
        images.Add(filename);

        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:");
                System.Console.WriteLine(ocrResult.GetText());
                System.Console.WriteLine();
            }

            // shutdown the Tesseract OCR engine
            tesseractOcr.Shutdown();
        }

        // free images
        images.ClearAndDisposeItems();
    }
}