Tutorial: Detect and Extract MICR - Console C#

Posted on 2020-05-15 Nick Villalobos

MICR detection and extraction technology is a very important piece of many applications in the banking, finance, legal, and insurance industries that can’t afford to rely on slow, error-prone manual data entry. The MICR line at the bottom of all checks consists of three separate numbers, which are the check number, account number, and bank routing number. The MICR font is made out of a magnetic ink that is intended to limit check fraud. The reason magnetic ink is used is because it allows computers to recognize the characters even if they have been covered by a signature, cancellation marks, or other types of marks.

With LEADTOOLS, you can recognize both MICR E-13B and CMC-7 fonts found on all bank checks. Developers can easily create MICR solutions by loading images of checks from a file, scanning checks, or taking pictures with cameras, tablets or mobile devices. Not only will these advanced MICR libraries automatically detect the font, they will also look at all other fields on the check, such as the amount, date, name, and even extract the signature as an image. All of this technology is powered by LEAD's patented machine learning OCR technology.

The below code shows you everything needed to create a MICR solution in a C# console application. If you want a complete step-by-step tutorial, check out our Detect and Extract MICR.



   static void RunMICRDetectionRecogntion(RasterImage image) 
{ 
    using (RasterCodecs codecs = new RasterCodecs()) 
    { 
        StringBuilder sb = new StringBuilder(); 
 
        BankCheckReader micrReader = new BankCheckReader(); 
 
        IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD, false); 
        ocrEngine.Startup(codecs, null, null, @"C:\LEADTOOLS 20\Bin\Common\OcrLEADRuntime"); 
        micrReader.OcrEngine = ocrEngine; 
        // MICR Code Detection searches for E13b MICR font type 
        MICRCodeDetectionCommand e13bCmd = new MICRCodeDetectionCommand 
        { 
            SearchingZone = new LeadRect(0, 0, image.Width, image.Height) 
        }; 
        e13bCmd.Run(image); 
 
        // Run CMC7 Detection 
        CMC7CodeDetectionCommand cmc7Cmd = new CMC7CodeDetectionCommand(); 
        cmc7Cmd.Run(image); 
        // If E13b MICR code found 
        if (e13bCmd.MICRZone != LeadRect.Empty) 
        { 
            micrReader.MicrFontType = BankCheckMicrFontType.E13b; 
            micrReader.ProcessImage(image); 
 
            foreach (var value in micrReader.Results) 
            { 
                if (value.Key != "Signature") 
                { 
                    sb.Append("\n"); 
                    sb.Append($"Field Name: {value.Key}\n"); 
                    sb.Append($"Field Value: {value.Value.Text}\n"); 
                } 
            } 
            Console.WriteLine(sb.ToString()); 
            Console.ReadLine(); 
        } 
        // If CMC7 MICR code found 
        else if (cmc7Cmd.CMC7Zone != LeadRect.Empty) 
        { 
            micrReader.MicrFontType = BankCheckMicrFontType.Cmc7; 
            micrReader.ProcessImage(image); 
 
            foreach (var value in micrReader.Results) 
            { 
                if (value.Key != "Signature") 
                { 
                    sb.Append("\n"); 
                    sb.Append($"Field Name: {value.Key}\n"); 
                    sb.Append($"Field Value: {value.Value.Text}\n"); 
                } 
            } 
            Console.WriteLine(sb.ToString()); 
            Console.ReadLine(); 
        } 
        else 
        { 
            Console.WriteLine("No MICR text detected!"); 
        } 
        ocrEngine.Shutdown(); 
    } 
}

Try it out!

To test this for yourself, make sure to get the latest LEADTOOLS SDK evaluation for free from our site, if you have not already. This trial is good for 60 days and comes with unlimited chat and email support.

Support

Need help getting this sample up and going? Contact our support team for free technical support! For pricing or licensing questions, you can contact our sales team (sales@leadtools.com) or call us at 704-332-5532.


Stay tuned because, as promised in our previous post, "Convert Video to HEVC/H.265 and AVC/H.264 in C++", we'll be featuring a lot more tutorials that programmers can use to develop applications that directly impact data capture, recognition, exchange, and other pressing business needs.

LEADTOOLS Blog

LEADTOOLS Powered by Apryse,the Market Leading PDF SDK,All Rights Reserved