L_OcrPage_ExtractZoneMICRData

#include "ltocr.h"

L_LTOCR_API L_INT EXT_FUNCTION L_OcrPage_GetText(page, zoneIndex, data)

L_OcrPage page; handle to the OCR page
L_UINT zoneIndex; zone index
L_OcrMICRData* data; address for L_OcrMICRData structure variable to be updated with zone MICR data

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

Parameter Description
page Handle to the OCR page.
zoneIndex Zero based index of the zone.
data Address for L_OcrMICRData structure variable to be updated with extracted zone MICR data from the recognition data.

Returns

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

LTOCR
For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.
See Also
Functions: L_OcrPage_Destroy, L_OcrPage_FromBitmap, L_OcrPage_GetBitmap, L_OcrPage_SetBitmap, L_OcrPage_GetOverlayBitmap, L_OcrPage_SetOverlayBitmap, L_OcrPage_SetBitmapChangedCallback, L_OcrPage_IsInverted, L_OcrPage_GetRotateAngle, L_OcrPage_GetDeskewAngle, L_OcrPage_AutoPreprocess, L_OcrPage_AutoZone, L_OcrPage_GetZoneCount, L_OcrPage_InsertZone, L_OcrPage_AddZone, L_OcrPage_IndexOfZone, L_OcrPage_GetZoneAt, L_OcrPage_SetZoneAt, L_OcrPage_RemoveZone, L_OcrPage_RemoveZoneAt, L_OcrPage_ClearZones, L_OcrPage_GetZoneCells, L_OcrPage_SetZoneCells, L_OcrPage_HitTestZone, L_OcrPage_IsRecognized, L_OcrPage_Recognize, L_OcrPage_Unrecognize, L_OcrPage_GetRecognizeStatistics, L_OcrPage_GetRecognizedCharacters, L_OcrPage_SetRecognizedCharacters, L_OcrPage_FreePageCharacters, L_OcrPage_GetZoneWords, L_OcrPage_FreeWords, L_OcrPage_GetText, L_OcrPage_DetectLanguages, L_OcrPage_LoadZonesFile, L_OcrPage_SaveZonesFile, L_OcrPage_SaveXml, L_OcrPage_GetAutoPreprocessValues
Topics: Programming with LEADTOOLS OCR Module - LEAD Engine
Starting and Shutting Down the OCR Engine
Recognizing OCR Pages
Working With OCR Pages

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 20.0.2018.1.19
Products | Support | Contact Us | Copyright Notices
© 1991-2018 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS OCR Module - LEAD Engine C API Help