L_OcrPage_LoadZonesFile

#include "ltocr.h"

L_LTOCR_API L_INT EXT_FUNCTION L_OcrPage_LoadZonesFile(page, fileName, pageNumber)

L_OcrPage page; handle to the OCR page
const L_TCHAR* fileName; the name of the file containing the zones to load
L_UINT pageNumber; 1-based page number to load its zones

Loads zones from a multi-page zones disk file.

Parameter Description
page Handle to the OCR page.
fileName The name of the file containing the zones to load.
pageNumber 1-based page number to load its zones.

Returns

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

Comments

To save the zones of OCR pages, you can use L_OcrPage_SaveZonesFile.

L_OcrPage_SaveZonesFile method save the zones of a particular OCR page to a multi-page disk file. If the file exist previously, this method will replace the zones specified in 'pageNumber' with the zones of the L_OcrPage. If the file does not contain zones for the specified page number, the zones will be appended to the file at the end and can be loaded later using L_OcrPage_LoadZonesFile.

If you wish to save all L_OcrDocument pages zones to file then you have to loop through the OCR document pages saving each page zones to the same file and the save method will append the zones of each page to the file giving you a multi-page zones file. The saved data will contain the page number of the zones. To load these zones, you also have to loop through all you OCR document pages loading each page zones separately passing the L_OcrPage_LoadZonesFile method the page number you wish to load its zones.

Note on loading zones from a multi-page zone file: If the file does not contain zones data with the correct page number, the engine will not load any zones for this page. After the method returns, any OCR page that did not have zones data will contain zero zones. You can then use L_OcrPage_AutoZone if required to re-zone this page.

The zones of this page will first be cleared prior to loading the new items.

Saving zones to an external file or could be useful when you are processing forms. For example, you can load one of the forms and automatically find the zones inside it using L_OcrPage_AutoZone, if the automatic zone detection was not 100 percent satisfactory, you can update the page zones manually and then save the result with L_OcrPage_SaveZonesFile. Once the zones are saved, you can now process all similar forms in the following manner:

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_ExtractZoneMICRData, L_OcrPage_DetectLanguages, L_OcrPage_SaveZonesFile, L_OcrPage_SaveXml, L_OcrPage_GetAutoPreprocessValues
Topics: Programming with LEADTOOLS OCR Advantage
Starting and Shutting Down the OCR Engine
Recognizing OCR Pages
Working With OCR Pages

Example

#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName 
#define OCR_ADVANTAGE_RUNTIME_DIR TEXT("C:\\LEADTOOLS 19\\Bin\\Common\\OcrAdvantageRuntime") 
L_INT L_OcrPage_LoadZonesFileExample() 
{ 
   BITMAPHANDLE bitmap1 = { 0 }, 
   bitmap2 = { 0 }; 
   L_OcrEngine ocrEngine = NULL; 
   L_OcrPage ocrPage1 = NULL, 
   ocrPage2 = NULL; 
   L_UINT zoneCount = 0; 
   // Create an instance of the engine 
   L_INT retCode = L_OcrEngineManager_CreateEngine(L_OcrEngineType_Advantage, &ocrEngine); 
   if(retCode != SUCCESS) 
      return retCode; 
   // Start the engine using default parameters 
   L_OcrEngine_Startup(ocrEngine, NULL, OCR_ADVANTAGE_RUNTIME_DIR); 
   // Load images to process 
   L_LoadBitmap(MAKE_IMAGE_PATH(L_TEXT("Ocr1.tif")), &bitmap1, sizeof(BITMAPHANDLE), 0, ORDER_RGB, NULL, NULL); 
   L_LoadBitmap(MAKE_IMAGE_PATH(L_TEXT("Ocr2.tif")), &bitmap2, sizeof(BITMAPHANDLE), 0, ORDER_RGB, NULL, NULL); 
   // Add an image to OCR page. Bitmaps will be freed when OCR Page is destroyed 
   L_OcrPage_FromBitmap(ocrEngine, &ocrPage1, &bitmap1, L_OcrBitmapSharingMode_AutoFree, NULL, NULL); 
   L_OcrPage_FromBitmap(ocrEngine, &ocrPage2, &bitmap2, L_OcrBitmapSharingMode_AutoFree, NULL, NULL); 
   // Auto-zone all the pages 
   L_OcrPage_AutoZone(ocrPage1, NULL, NULL); 
   L_OcrPage_AutoZone(ocrPage2, NULL, NULL); 
   std::cout << "Number of zones after auto-zone:\n"; 
   L_OcrPage_GetZoneCount(ocrPage1, &zoneCount); 
   std::cout << "  Page 1 has " << zoneCount << " zones.\n"; 
   L_OcrPage_GetZoneCount(ocrPage2, &zoneCount); 
   std::cout << "  Page 2 has " << zoneCount << " zones.\n"; 
   // Save the zones to a disk file 
   L_OcrPage_SaveZonesFile(ocrPage1, MAKE_IMAGE_PATH(L_TEXT("L_OcrLanguageManagerExample.xml")), 1, NULL); 
   L_OcrPage_SaveZonesFile(ocrPage2, MAKE_IMAGE_PATH(L_TEXT("L_OcrLanguageManagerExample.xml")), 2, NULL); 
   // Clear the zones 
   L_OcrPage_ClearZones(ocrPage1); 
   L_OcrPage_ClearZones(ocrPage2); 
   // Show the zones now: 
   std::cout << "Number of zones after saving the zones to file and then clear:\n"; 
   L_OcrPage_GetZoneCount(ocrPage1, &zoneCount); 
   std::cout << "  Page 1 has " << zoneCount << " zones.\n"; 
   L_OcrPage_GetZoneCount(ocrPage2, &zoneCount); 
   std::cout << "  Page 2 has " << zoneCount << " zones.\n"; 
   // Re-load the zones 
   L_OcrPage_LoadZonesFile(ocrPage1, MAKE_IMAGE_PATH(L_TEXT("L_OcrLanguageManagerExample.xml")), 1); 
   L_OcrPage_LoadZonesFile(ocrPage2, MAKE_IMAGE_PATH(L_TEXT("L_OcrLanguageManagerExample.xml")), 2); 
   // Show the zones now: 
   std::cout << "Number of zones after loading the zones from file: \n"; 
   L_OcrPage_GetZoneCount(ocrPage1, &zoneCount); 
   std::cout << "  Page 1 has " << zoneCount << " zones.\n"; 
   L_OcrPage_GetZoneCount(ocrPage2, &zoneCount); 
   std::cout << "  Page 2 has " << zoneCount << " zones.\n"; 
   //CLEANUP 
   if(ocrPage1 != NULL) 
      L_OcrPage_Destroy(ocrPage1); 
   if(ocrPage2 != NULL) 
      L_OcrPage_Destroy(ocrPage2); 
   if(ocrEngine != NULL) 
      L_OcrEngine_Destroy(ocrEngine); 
   return SUCCESS; 
} 

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS Advantage OCR C API Help