L_OcrPage_ExtractZoneMICRData

#include "ltocr.h"

L_LTOCR_API L_INT EXT_FUNCTION L_OcrPage_GetText(page, zoneIndex, data)

Extracts the Magnetic ink character recognition (MICR) data for this zone recognition data.

Parameters

L_OcrPage page

Handle to the OCR page.

L_UINT zoneIndex

Zero based index of the zone.

L_OcrMICRData* data

Address for L_OcrMICRData structure variable to be updated with extracted zone MICR data from the recognition data.

Returns

Value Meaning
SUCCESS The function was successful.
< 1 An error occurred. Refer to Return Codes.

Comments

This method will try to extract the Magnetic ink character recognition (MICR) data from this zone recognition data by reading the characters and formatting them into an L_OcrMICRData data structure.

This method should typically be used only if the zone type is set to L_OcrZoneType_MICR. The method will use the MICR standard to parse the result such as 'Amount' and 'Routing number' and put them into the equivalent properties of L_OcrMICRData.

In LEADTOOLS OCR Module - LEAD Engine, the related "Recognition.CharacterFilter.PostprocessMICR" setting controls how the page will process MICR data. When the value if this setting is L_TRUE, then the engine will drop any characters not in the MICR standard from the result.

Required DLLs and Libraries

See Also

Functions

Topics

Example

L_INT L_OcrPage_ExtractZoneMICRDataExample() 
{ 
   BITMAPHANDLE bitmap = { 0 }; 
   L_OcrEngine ocrEngine = NULL; 
   L_OcrPage ocrPage = NULL; 
 
   // Create an instance of the engine 
   L_INT retCode = L_OcrEngineManager_CreateEngine(L_OcrEngineType_Advantage, &ocrEngine); 
   if(retCode == SUCCESS) 
   { 
      // Start the engine using default parameters 
      retCode = L_OcrEngine_Startup(ocrEngine, NULL, OCR_ADVANTAGE_RUNTIME_DIR); 
      if(retCode != SUCCESS) 
         return retCode; 
 
      // Load a page to be recognized 
      retCode = L_LoadBitmap(MAKE_IMAGE_PATH(L_TEXT("MICR_SAMPLE.tif")), &bitmap, sizeof(BITMAPHANDLE), 0, ORDER_RGB, NULL, NULL); 
      if(retCode != SUCCESS) 
         goto CLEANUP; 
 
      // Add an image to OCR page. don't transfer ownership of the bitmap to the page 
      retCode = L_OcrPage_FromBitmap(ocrEngine, &ocrPage, &bitmap, L_OcrBitmapSharingMode_None, NULL, NULL); 
      if(retCode != SUCCESS) 
         goto CLEANUP; 
 
      L_RECT rcSearchArea = {0}; 
      L_RECT rcMicrArea = {0}; 
      rcSearchArea.left = 0; 
      rcSearchArea.top = 0; 
      rcSearchArea.right = bitmap.Width; 
      rcSearchArea.bottom = bitmap.Height; 
      retCode = L_MICRDetection(&bitmap, rcSearchArea, &rcMicrArea, 0); 
      if(rcMicrArea.right - rcMicrArea.left == 0 && rcMicrArea.bottom - rcMicrArea.top == 0) 
      { 
         // if empty rect was returned then L_MICRDetection function detected no MICR zone, so clean up and exit 
         goto CLEANUP; 
      } 
 
      // Create MICR zone and insert it into the OCR page 
      L_OcrZone micrZone = {0}; 
      L_OcrZone_Default(&micrZone); 
      micrZone.ZoneType = L_OcrZoneType_Micr; 
      micrZone.Bounds = rcMicrArea; 
      retCode = L_OcrPage_InsertZone(ocrPage, 0, &micrZone); 
      if(retCode != SUCCESS) 
         goto CLEANUP; 
       
      // Recognize the page 
      retCode = L_OcrPage_Recognize(ocrPage, NULL, NULL); 
      if(retCode != SUCCESS) 
         goto CLEANUP; 
 
      L_INT zoneIndex = -1; 
      L_OcrPage_IndexOfZone(ocrPage, &micrZone, &zoneIndex); 
      if(retCode != SUCCESS) 
         goto CLEANUP; 
 
      L_OcrMICRData micrData = {0}; 
      retCode = L_OcrPage_ExtractZoneMICRData(ocrPage, zoneIndex, &micrData); 
      if(retCode != SUCCESS) 
         goto CLEANUP; 
 
      // show the recognized MICR zone data 
      std::wcout << L"MICR zone data:" << std::endl; 
      std::wcout << L"Auxiliary: " << micrData.Auxiliary << std::endl; 
      std::wcout << L"EPC: " << micrData.EPC << std::endl; 
      std::wcout << L"Routing: " << micrData.Routing << std::endl; 
      std::wcout << L"Account: " << micrData.Account << std::endl; 
      std::wcout << L"CheckNumber: " << micrData.CheckNumber << std::endl; 
      std::wcout << L"Amount: " << micrData.Amount << std::endl; 
 
      // Un-recognize page 
      L_OcrPage_Unrecognize(ocrPage); 
 
      // remove the zone that we added 
      L_OcrPage_RemoveZone(ocrPage, &micrZone); 
 
      // Adding the page to a file based document will take a snap shot of the recognition data and store it in the document. At this 
      // point, the page is no longer needed. So destroy it to free up memory not used anymore 
      L_OcrPage_Destroy(ocrPage); 
      // Set the handle to NULL so we do not free it in our clean-up code 
      ocrPage = NULL; 
   } 
 
CLEANUP: 
   if(bitmap.Flags.Allocated) 
      L_FreeBitmap(&bitmap); 
 
   if(ocrPage != NULL) 
      L_OcrPage_Destroy(ocrPage); 
 
   if(ocrEngine != NULL) 
      L_OcrEngine_Destroy(ocrEngine); 
 
   return retCode; 
} 
Help Version 21.0.2021.7.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS OCR Module - LEAD Engine C API Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.