L_OcrPage_SetZoneCells

#include "ltocr.h"

L_LTOCR_API L_INT EXT_FUNCTION L_OcrPage_SetZoneCells(page, index, cells, count)

L_OcrPage page; handle to the OCR page
L_INT index; index of the zones contains the cells
const L_OcrZoneCell* cells; array of L_OcrZoneCell structure to update the zone at the specified index with
L_UINT count; number of elements inside the cells array

Sets the cells of a zone.

Parameter Description
page Handle to the OCR page.
index Zone index to remove.
cells Array of L_OcrZoneCell structure to update the zone at the specified index with. pass NULL for this parameter to clear the zone cells.
count Number of elements inside the cells array.

Returns

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

Comments

Sets the cells of a zone. Only zone of type table (L_OcrZoneType_Table) can contain cells.

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_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_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_SetZoneCellsExample() 
{ 
   BITMAPHANDLE bitmap = { 0 }; 
   L_OcrEngine ocrEngine = NULL; 
   L_OcrPage ocrPage = NULL; 
   L_OcrDocumentManager ocrDocumentManager = NULL; 
   L_OcrDocument ocrDocument = NULL; 
 
   // 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 an image 
   retCode = L_LoadBitmap(MAKE_IMAGE_PATH(L_TEXT("Clean.tif")), &bitmap, sizeof(BITMAPHANDLE), 0, ORDER_RGB, NULL, NULL); 
   if(retCode != SUCCESS) 
      goto CLEANUP; 
 
   // Add image to OCR page 
   retCode = L_OcrPage_FromBitmap(ocrEngine, &ocrPage, &bitmap, L_OcrBitmapSharingMode_AutoFree, NULL, NULL); 
   if(retCode != SUCCESS) 
   { 
      L_FreeBitmap(&bitmap); 
      goto CLEANUP; 
   } 
 
   // Transfer ownership to OCR page 
   bitmap.Flags.Allocated = 0; 
 
   // Get the setting manager 
   L_OcrSettingManager ocrSettingManager = NULL; 
   L_OcrEngine_GetSettingManager(ocrEngine, &ocrSettingManager); 
 
   // Remove the "Table Cells as Zones" flag from the Recognition.Zoning.Options setting in order to detect the whole  
   // table as one zone so we can get its cells later 
   retCode = L_OcrSettingManager_SetStringValue(ocrSettingManager, TEXT("Recognition.Zoning.Options"), TEXT("Detect Text,Detect Graphics,Detect Table,Detect Accurate Zones,Use Advanced Table Detection")); 
   if(retCode != SUCCESS) 
      goto CLEANUP; 
 
   // Auto zone the page 
   retCode = L_OcrPage_AutoZone(ocrPage, NULL, NULL); 
   if(retCode != SUCCESS) 
      goto CLEANUP; 
 
   // Loop through page zones to find the table zone and manipulate its cells 
   L_UINT zonesCount = 0; 
   L_OcrPage_GetZoneCount(ocrPage, &zonesCount); 
   for(L_UINT i = 0; i < zonesCount; i++) 
   { 
      L_OcrZone zone = {0}; 
      zone.StructSize = sizeof(L_OcrZone); 
      L_OcrPage_GetZoneAt(ocrPage, i, &zone); 
 
      if(zone.ZoneType == L_OcrZoneType_Table) 
      { 
         L_OcrZoneCell* cells = NULL; 
         L_UINT cellsCount = 0; 
         L_OcrPage_GetZoneCells(ocrPage, i, &cells, &cellsCount); 
         if(cellsCount > 0) 
         { 
            // you can do any change you want here for the zone cells, below we will replace the first cell with another one we create 
            L_OcrZoneCell newCell = {0}; 
            L_OcrCell_Default(&newCell); 
            newCell.Bounds = cells[0].Bounds; 
            newCell.LeftBorderWidth = 2; 
            newCell.TopBorderWidth = 2; 
            newCell.RightBorderWidth = 2; 
            newCell.BottomBorderWidth = 2; 
            cells[0] = newCell; 
 
            // set eh cells back to engine after we changed them 
            L_OcrPage_SetZoneCells(ocrPage, i, cells, cellsCount); 
         } 
      } 
   } 
 
   // Recognize the page (automatically zoned) 
   L_OcrPage_Recognize(ocrPage, NULL, NULL); 
 
   // Recognize and save the file to the output format 
   L_OcrEngine_GetDocumentManager(ocrEngine, &ocrDocumentManager); 
 
   // Create file-based OCR document 
   L_OcrDocumentManager_CreateDocument(ocrDocumentManager, &ocrDocument, L_OcrCreateDocumentOptions_AutoDeleteFile, NULL); 
 
   // In Document File Mode, add OcrPage to OcrDocument after recognition 
   L_OcrDocument_AddPage(ocrDocument, ocrPage); 
   L_OcrPage_Destroy(ocrPage); 
 
   // Save the document we have 
   L_OcrDocument_Save(ocrDocument, MAKE_IMAGE_PATH(L_TEXT("Output.pdf")), DOCUMENTFORMAT_PDF, NULL, NULL); 
 
CLEANUP: 
   if(ocrDocument != NULL) 
      L_OcrDocument_Destroy(ocrDocument); 
 
   if(ocrEngine != NULL) 
      L_OcrEngine_Destroy(ocrEngine); 
   return SUCCESS; 
} 

Help Version 20.0.2018.2.22
Products | Support | Contact Us | Copyright Notices
© 1991-2018 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS OCR Module - LEAD Engine C API Help