Sets the overlay bitmap of this L_OcrPage.


#include "ltocr.h"

L_LTOCR_API L_INT EXT_FUNCTION L_OcrPage_SetOverlayBitmap(page, bitmapHandle)


L_OcrPage page

Handle to the OCR page.

BITMAPHANDLE* bitmapHandle

BITMAPHANDLE to use to update the page overlay bitmap.


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


The overlay image of an L_OcrPage will be used when the image is saved by an L_OcrDocument in the following situations:

By default, the overlay image is the original image used to create the page. It is the same value obtained by calling L_OcrPage_GetBitmap with L_OcrPageBitmapType_Original option.

In some situation, the user might want to use a different bitmap as the overlay. For example, a smaller version is passed to the OCR engine to conserve memory while the original version will only be used on save purposes in a PDF with image/text option. You can call L_OcrPage_SetOverlayBitmap before saving the document (memory-based) or adding the page to the document (file-based) and the engine will use this new bitmap as the overlay value. If auto-preprocessing was performed on the page through L_OcrPage_AutoPreprocess, then the same values might need to be applied to the overlay as well. Use L_OcrPage_GetAutoPreprocessValues to get the accumulative values of any inversion, rotation or deskewing applied by the pre-processor.

To clear the temporarily overlay image, call L_OcrPage_SetOverlayBitmap with a NULL value.

To get the overlay image at any time, call L_OcrPage_GetOverlayBitmap. Note that this property will return the same image reference passed to the last L_OcrPage_SetOverlayBitmap call. It will not return the original image.

The overlay bitmap is not freed by this L_OcrPage.

Required DLLs and Libraries

See Also




L_INT L_OcrPage_SetOverlayBitmapExample() 
   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) 
      // Start the engine using default parameters 
      retCode = L_OcrEngine_Startup(ocrEngine, NULL, OCR_LEAD_RUNTIME_DIR); 
      if(retCode != SUCCESS) 
         return retCode; 
      // Load a page to be recognized 
      retCode = L_LoadBitmap(MAKE_IMAGE_PATH(L_TEXT("Ocr1.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 we will control this original image 
      retCode = L_OcrPage_FromBitmap(ocrEngine, &ocrPage, &bitmap, L_OcrBitmapSharingMode_None, NULL, NULL); 
      if(retCode != SUCCESS) 
         goto CLEANUP; 
      // Get OCR page default overlay bitmap and save it to disk 
      BITMAPHANDLE origOverlayBitmap = {0}; 
      retCode = L_OcrPage_GetOverlayBitmap(ocrPage, &origOverlayBitmap, sizeof(BITMAPHANDLE)); 
      if(retCode != SUCCESS) 
         goto CLEANUP; 
      // if the OCR page has overlay bitmap they save it before we change it 
         L_SaveBitmap(TEXT("OcrPageOrigOverlayBitmap.tif"), &origOverlayBitmap, FILE_CCITT_GROUP4, origOverlayBitmap.BitsPerPixel, 2, NULL); 
      // Apply some auto preprocessing on the image 
      L_OcrPage_AutoPreprocess(ocrPage, L_OcrAutoPreprocessPageCommands_All, NULL, NULL); 
      // resize down our original bitmap into half and set it as the OCR page overlay bitmap to conserve memory. 
      retCode = L_SizeBitmap(&bitmap, bitmap.Width / 2, bitmap.Height / 2, SIZE_RESAMPLE); 
      if(retCode != SUCCESS) 
         goto CLEANUP; 
      // Now you might want to apply the same auto preprocessing commands applied to the OCR page into the overlay bitmap  
      // before you set it, to do so, you need to call L_OcrPage_GetAutoPreprocessValues function first to determine what 
      // kind of preprocessing values were applied to the OCR page 
      L_OcrPageAutoPreprocessValues autoPreprocessValues = {0}; 
      retCode = L_OcrPage_GetAutoPreprocessValues(ocrPage, &autoPreprocessValues); 
      if(retCode == SUCCESS) 
            L_InvertBitmap(&bitmap, 0); 
         if(autoPreprocessValues.DeskewAngle > 0) 
            L_DeskewBitmap(&bitmap, NULL,RGB(0, 0, 0), DSKW_PROCESS | DSKW_RESAMPLE); 
         if(autoPreprocessValues.RotationAngle > 0) 
            L_RotateBitmap(&bitmap, autoPreprocessValues.RotationAngle, ROTATE_RESAMPLE, RGB(0, 0, 0)); 
      // Now save our updated overlay bitmap to disk 
      L_SaveBitmap(TEXT("OcrPageUpdatedOverlayBitmap.tif"), &bitmap, FILE_CCITT_GROUP4, bitmap.BitsPerPixel, 2, NULL); 
      retCode = L_OcrPage_SetOverlayBitmap(ocrPage, &bitmap); 
      if(retCode != SUCCESS) 
         goto CLEANUP; 
      // Recognize the page 
      // Note: Recognize can be called without calling AutoZone or manually adding zones. 
      // The engine will check and automatically auto-zones the page. 
      retCode = L_OcrPage_Recognize(ocrPage, NULL, NULL); 
      if(retCode != SUCCESS) 
         goto CLEANUP; 
      //Get the document manager 
      retCode = L_OcrEngine_GetDocumentManager(ocrEngine, &ocrDocumentManager); 
      if(retCode != SUCCESS) 
         goto CLEANUP; 
      // Create file-based OCR document 
      retCode = L_OcrDocumentManager_CreateDocument(ocrDocumentManager, &ocrDocument, L_OcrCreateDocumentOptions_AutoDeleteFile, NULL); 
      if(retCode != SUCCESS) 
         goto CLEANUP; 
      // Add page to the document. 
      retCode = L_OcrDocument_AddPage(ocrDocument, ocrPage); 
      if(retCode != SUCCESS) 
         goto CLEANUP; 
      // 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 
      // Set the handle to NULL so we do not free it in our clean-up code 
      ocrPage = NULL; 
      // Save the document we have as PDF Image/Text 
      // Get the format options for PDF 
      DOCWRTPDFOPTIONS pdfOptions; 
      pdfOptions.Options.uStructSize = sizeof(DOCWRTPDFOPTIONS); 
      L_OcrDocumentManager_GetFormatOptions(ocrDocumentManager, DOCUMENTFORMAT_PDF, &pdfOptions.Options); 
      // Set the PDF ImageOverText option to TRUE 
      pdfOptions.bImageOverText = L_TRUE; 
      // Give the engine our updated PDF options 
      L_OcrDocumentManager_SetFormatOptions(ocrDocumentManager, DOCUMENTFORMAT_PDF, &pdfOptions.Options); 
      retCode = L_OcrDocument_Save(ocrDocument, MAKE_IMAGE_PATH(L_TEXT("Output.pdf")), DOCUMENTFORMAT_PDF, NULL, NULL); 
      // Now if you opened the saved PDF file you will see our resized image shown as the PDF image over text  
      // instead of the original OCR page bitmap. 
   if(ocrPage != NULL) 
   if(ocrDocument != NULL) 
   if(ocrEngine != NULL) 
   return retCode; 
Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.


Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.