L_OcrPage_SetZoneCells

Summary

Sets the cells of a zone.

Syntax

#include "ltocr.h"

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

Parameters

L_OcrPage page

Handle to the OCR page.

L_INT index

Zone index to remove.

const L_OcrZoneCell* 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.

L_UINT count

Number of elements inside the cells array.

Returns

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

See Also

Functions

Topics

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_LEAD, &ocrEngine); 
   if(retCode != SUCCESS) 
      return retCode; 
 
   // Start the engine using default parameters 
   L_OcrEngine_Startup(ocrEngine, NULL, OCR_LEAD_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 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

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