L_OcrPage_LoadZonesFile

#include "ltocr.h"

L_LTOCR_API L_INT EXT_FUNCTION L_OcrPage_LoadZonesFile(page, fileName, pageNumber)

Loads zones from a multipage zones disk file.

Parameters

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.

Returns

Value Meaning
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 multipage 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 multipage 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 multipage 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

See Also

Functions

Topics

Example

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 20.0.2020.4.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2020 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS OCR Module - LEAD Engine C API Help