#include "ltwrappr.h"

virtual L_INT LBitmap::Deskew(pnAngle=NULL, crBack, uFlags)

L_INT32 * pnAngle;

address of the variable to be updated


fill color

L_UINT uFlags;


Rotates the specified bitmap to straighten it.

This function contains a special algorithm for detecting the skewed checks, for more information refer to the comments section below.

Parameter Description
pnAngle NULL or the address of the variable to be updated with the amount that the function rotates the image. The amount of rotation is expressed in hundredths of degrees. For example, 500 means 5 degrees clockwise. You can pass NULL if you do not need to check the amount of rotation. Valid values range from -2000 to 2000.
crBack Color used to fill the background following rotation. This is used only if DSK_FILL is set in uFlags.
uFlags Flags that indicate whether or not to deskew the image and what background color to use. You can use a bitwise OR (|) to specify one flag from each group.
  The following flags indicate whether to deskew the image after the function finds the skew angle:
  Value Meaning
  DSKW_PROCESS [0x00000000] Deskew (rotate) the image.
  DSKW_NOPROCESS [0x00000001] Dont deskew (rotate) the image. Generally this flag is used to find the angle of rotation.
  The following flags indicate what background color to use:
  Value Meaning
  DSKW_FILL [0x00000000] Use the color in crBack to fill areas exposed after rotation.
  DSKW_NOFILL [0x00000010] Let the function automatically find the suitable background color used to fill areas exposed after rotation. crBack is ignored in this case.
  The following flags indicate which type of interpolation to perform:
  Value Meaning
  DSKW_LINEAR [0x00000000] Do not perform interpolation when rotating.
  DSKW_RESAMPLE [0x00001000] Perform bilinear interpolation when rotating.
  DSKW_BICUBIC  [0x00002000] Perform bicubic interpolation when rotating.
  The following flags indicate image type:
  Value Meaning
  DSKW_DOCUMENTIMAGE [0x00000000] The image contains text only.
  DSKW_DOCUMENTANDPICTURE [0x00010000] The image contains text and pictures or light text.
  DSKW_NORMALSPEEDROTATE [0x00000000] Rotate at normal speed (high quality).  This is the default value.
  DSKW_HIGHSPEEDROTATE [0x00100000] Rotate at high speed (moderate quality, only for 1-bit images)
  The following flags indicates whether to perform a  preprocessing operation to enhance the results. Possible values are: (For Version 16 only)
  Value Meaning
  DSKW_PERFORM_PREPROCESSING [0x00000000] Perform  pre processing operations, it is recommended to use this with the images that contain black border as result of scanning. This only works with 1-bit document images. This is used to enhance the accuracy.
  DSKW_DONT_PERFORM_PREPROCESSING 0x10000000] Do not Perform  pre processing operations.
  The following flags indicates the skew angle detection technique. Possible values are:
  DSKW_SELECTIVE_DETECTION [0x00000000] Detect the skew angle selectively using the important features of the document. This only works with 1-bit document images. This is used to enhance the accuracy.
   DSKW_NORMAL_DETECTION [0x20000000] Detect the skew angle normally using all the features of the document.
  The following flags indicates whether and which bank check algorithm to use.
  Value Meaning
  DSKW_DONT_USE_CHECK_DESKEW [0x00000000] Do not perform any of the bank check algorithms. Perform the ordinary deskew. This is the default value.
  DSKW_USE_CHECK_DESKEW [0x01000000] Use the bank check algorithm to deskew the bitmap. This algorithm considers many features common to standard bank checks in order to determine orientation.
  DSKW_USE_CHECK_DESKEW_DETECT_LINES [0x02000000] Use the bank check line detection algorithm to deskew the image



The function was successful.

< 1

An error occurred. Refer to Return Codes.


This function contains a special algorithm for detecting the skewed checks, by adding the (DSKW_USE_CHECK_DESKEW | DSKW_USE_CHECK_DESKEW_DETECT_LINES) flags to uFlags parameter.

This function typically is used to automatically straighten scanned images, including bank checks.

If the flags use DSKW_NOPROCESS, the function will return the deskew angle in the pnAngle variable, without image rotation.

The calculated rotation is limited to 20 degrees in either direction. This function is intended for images, such as scanned documents, that are mainly horizontal lines of text. The results are less predictable with other types of images.

To update a status bar or detect a user interrupt during execution of this function, refer to LBase::EnableStatusCallback.

This function does not support 12 and 16-bit grayscale and 48 and 64-bit color images. If the image is 12 and 16-bit grayscale and 48 and 64-bit color, the function will not return an error.

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 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.

For more information, refer to Deskewing.

Required DLLs and Libraries


For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.


Win32, x64.

See Also


LBitmap::DeskewExt, LBitmap::Despeckle, LBitmap::WindowLevel, LBitmap::WindowLevelExt,  LBitmap::BlankPageDetector, LBitmap::AutoBinarize, LBitmap::DynamicBinary, LBitmap::AutoBinary, Class Members


Raster Image Functions: Doing Geometric Transformations


Raster Image Functions: Filtering Images


Processing an Image


Using Color Values in LEADTOOLS




Raster Image Functions: Processing an Image


Cleaning Up 1-Bit Images


#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName 
L_INT LBitmap__DeskewExample() 
   L_INT nRet; 
   LBitmap LeadBitmap; 
   L_INT32 lRotatedAngle; 
   L_TCHAR szDummyBuffer[50]; 
   nRet =LeadBitmap.Load(MAKE_IMAGE_PATH(TEXT("image1.cmp")), 0,ORDER_BGR); 
   if(nRet !=SUCCESS) 
      return nRet; 
   // Deskew the image, and get the angle with which the image was rotated 
   nRet =LeadBitmap.Deskew(&lRotatedAngle, RGB(0,0,0), DSKW_PROCESS | DSKW_NOFILL| DSKW_DOCUMENTIMAGE); 
   if(nRet !=SUCCESS) 
      return nRet; 
   wsprintf(szDummyBuffer, TEXT("The image was rotated with %d degrees"), lRotatedAngle/100); 
   MessageBox(0, szDummyBuffer, TEXT("Deskew"), MB_OK); 
   return SUCCESS; 

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS Raster Imaging C++ Class Library Help