Check OCR and MICR Data Extraction Using C#
This guide explains how to extract magnetic ink character recognition (MICR) information from documents. The MICR code is usually the last line in a bank check. The code is printed in magnetic ink for automatic reading and security reasons, and it can be read by devices using optical character recognition (OCR). GdPicture.NET’s OCR engine allows you to recognize the MICR information in bank checks. Both commonly used fonts — E-13B and CMC-7 — are supported. The engine automatically recognizes the MICR code, and you don’t need to specify the region of interest in the document.
Extracting MICR Information
To extract MICR information from a document, follow these steps:
-
Create a
GdPictureImaging
object and aGdPictureOCR
object. -
Select the image by passing its path to the
CreateGdPictureImageFromFile
method of theGdPictureImaging
object. -
Set the image with the
SetImage
method of theGdPictureOCR
object. -
Determine the font used in the MICR area of the document, and do one of the following:
-
If the MICR uses the E-13B font, run the OCR process by passing
OCRSpecialContext.MICRLineE13B
to theRunOCR
method of theGdPictureOCR
object. -
If the MICR uses the CMC-7 font, run the OCR process by passing
OCRSpecialContext.MICRLineCMC7
to theRunOCR
method of theGdPictureOCR
object.
-
-
Get the result of the OCR process as text with the
GetOCRResultText
method of theGdPictureOCR
object. -
Write the output to the console.
-
Release unnecessary resources.
The example below extracts MICR information from a document that uses the E-13B font:
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.MICRLineE13B); // Get the result of the OCR process as text. string micrData = gdpictureOCR.GetOCRResultText(resultId); // Write the output to the console. Console.WriteLine($"MICR information: {micrData}"); // 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.MICRLineE13B) ' Get the result of the OCR process as text. Dim micrData As String = gdpictureOCR.GetOCRResultText(resultId) ' Write the output to the console. Console.WriteLine($"MICR information: {micrData}") ' Release unnecessary resources. gdpictureImaging.ReleaseGdPictureImage(imageId) gdpictureOCR.ReleaseOCRResults() End Using End Using