LBitmap::HolePunchRemove

Summary

Finds and removes hole punches.

Syntax

#include "ltwrappr.h"

virtual L_INT LBitmap::HolePunchRemove(pHolePunchRemove, uFlags = 0)

Parameters

pHOLEPUNCH pHolePunchRemove

Pointer to the HOLEPUNCH structure that LEADTOOLS uses to remove hole punches.

L_UINT32 uFlags

Reserved for future use. Must be 0.

Returns

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

Comments

This function detects and removes hole punch marks that are common in scanned documents.

The behavior of this function can be modified by overriding LBitmap::HolePunchRemoveCallback.

This function does not support signed data images. It returns the error code ERROR_SIGNED_DATA_NOT_SUPPORTED if a signed data image is passed to this function.

This function works only on 1-bit black and white images.

This function does not support 32-bit grayscale images. It returns the error code ERROR_GRAY32_UNSUPPORTED if a 32-bit grayscale image is passed to this function.

Hole punch configurations may consist of 2 or more holes.

If a region is selected, only the selected region will be changed by this function. If no region is selected, the whole image will be processed.

Before calling this function, ensure that the hole punch is free of any other stray marks. If you do not, LBitmap::HolePunchRemove will not recognize the hole.

For example, the below image must have the vertical line removed. Use LBitmap::LineRemove to remove any horizontal or vertical lines from the image. Use other Document Cleanup functions to remove other imaging artifacts such as dots, blobs, borders, inverted text, bumps and nicks. This will have the added benefit of making your image smaller when compressed.

Once cleaned, LBitmap::HolePunchRemove will be able to identify and remove the hole punch mark.

Hole Punch Remove Function - Before

Hole Punch Remove Function - Before

Hole Punch Remove Function - After

Hole Punch Remove Function - After

View additional platform support for this Hole Punch Remove function.

Required DLLs and Libraries

Platforms

Win32, x64.

See Also

Functions

Topics

Example

This example updates a Windows region with removed hole punches
For the example, a Windows region is updated and then converted to a LEAD region
but in practice it would easier and faster to just return a LEAD region
The HOLEPUNCH_USE_DPI flag instructs the API to determine the size of the hole punches
based on the image DPI
The image is modified
The derived class LMyBitmap is used to override the HolePunchRemoveCallBack function
The callback member function is used to display information about each hole punch removed
The callback member function does NOT receive a Windows region

class LHolePunchRemoveBitmap : public LBitmap 
{ 
public: 
   LHolePunchRemoveBitmap(); 
   ~LHolePunchRemoveBitmap(); 
 
   virtual L_INT HolePunchRemoveCallBack(HRGN          hRgn,  
                                         PRECT         pBoundingRect,  
                                         L_INT32       iHoleIndex,   
                                         L_INT32       iHoleTotalCount,  
                                         L_INT32       iWhiteCount,  
                                         L_INT32       iBlackCount 
                                         ); 
}; 
 
LHolePunchRemoveBitmap::LHolePunchRemoveBitmap() 
{ 
} 
 
LHolePunchRemoveBitmap::~LHolePunchRemoveBitmap() 
{ 
} 
 
L_INT LBitmap__HolePunchRemoveExample(LBitmapWindow *pBitmapWindow) 
{ 
   L_INT32           nRet; 
   HOLEPUNCH         hr; 
 
   hr.uStructSize          = sizeof(HOLEPUNCH); 
   hr.iLocation      = HOLEPUNCH_LEFT; 
   hr.iMinHoleCount  = 2; 
   hr.iMaxHoleCount  = 4; 
   hr.pBitmapRegion  = NULL; 
 
   hr.uFlags         = HOLEPUNCH_SINGLE_REGION | HOLEPUNCH_USE_DPI | HOLEPUNCH_USE_COUNT | HOLEPUNCH_USE_LOCATION; 
 
   nRet = pBitmapWindow->HolePunchRemove(&hr); 
 
   if (nRet == SUCCESS) 
   { 
      //Delete the existing region 
      LBitmapRgn Region(pBitmapWindow); 
      if(Region.BitmapHasRgn()) 
      { 
         Region.Free(); 
      } 
 
      Region.SetRgnCombineMode(L_RGN_SET) ; 
      Region.SetRgnHandle(hr.hRgn); 
      DeleteObject(hr.hRgn); 
   } 
 
   return SUCCESS; 
} 
 
L_INT LHolePunchRemoveBitmap::HolePunchRemoveCallBack( 
   HRGN          hRgn,  
   PRECT         pBoundingRect,  
   L_INT32       iHoleIndex,   
   L_INT32       iHoleTotalCount,  
   L_INT32       iWhiteCount,  
   L_INT32       iBlackCount 
   ) 
{ 
   UNREFERENCED_PARAMETER(hRgn); 
 
   CString strMsg; 
 
   strMsg.Format ( 
      TEXT("Bounds[%d,%d][%d,%d]\tHole[%d] of [%d]\tWhiteCount[%d]\tBlackCount[%d]\n"), 
      pBoundingRect->left, 
      pBoundingRect->top, 
      pBoundingRect->right, 
      pBoundingRect->bottom, 
      iHoleIndex, 
      iHoleTotalCount, 
      iWhiteCount, 
      iBlackCount 
      ); 
   OutputDebugString(strMsg); 
 
   return SUCCESS_REMOVE;  
} 

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C++ Class Library Help

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