L_ImgKrnManualPerspectiveCorrection

#include "ltimgkrn.h"

L_LTIMGKRN_API L_INT L_ImgKrnManualPerspectiveCorrection(srcBitmap, data, destBitmap, structSize)

Corrects the view perspective of the image.

Parameters

BITMAPHANDLE *srcBitmap

Pointer to the source bitmap handle referencing the bitmap to be transformed.

const L_ImgKrnPerspectiveCorrectionData *data

Pointer to L_ImgKrnPerspectiveCorrectionData structure that contains a list of points that will be transformed to match the location of the mapped points list.

BITMAPHANDLE *destBitmap

Pointer to the handle of the transformed destination bitmap.

L_UINT structSize

Size, in bytes, of the structure pointed to by destBitmap.

Returns

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

Comments

Typically, this function is used as a preprocessing step when taking images from digital cameras. It changes the image based on a view perspective equation.

It is best to choose input points that are far away from each other.

Call L_ImgKrnDetectDocument to detect the points at the document corners.

Use the results from L_ImgKrnDetectDocument as the input points for the L_ImgKrnPerspectiveCorrectionData structure, which is used by the L_ImgKrnManualPerspectiveCorrection function to correct the perspective of a captured image.

Note: All functions with the L_ImgKrn prefix modify the underlying properties of the input BITMAPHANDLE, including but not limited to:

To avoid BITMAPHANDLE property fidelity loss, pass a copy of your BITMAPHANDLE to all L_ImgKrn* functions.

Required DLLs and Libraries

Platforms

Win32, x64, Linux.

See Also

Functions

Topics

Example

This example loads a bitmap and applies the manual perspective deskew filter.

L_INT KrnManualPerspectiveCorrectionExample(L_VOID) 
{ 
   L_INT ret; 
   BITMAPHANDLE bitmap;         /* Bitmap handle to hold the loaded image. */ 
   BITMAPHANDLE resultBitmap;   /* Bitmap handle to hold the result image. */ 
 
   /* Load the bitmap */ 
   ret = L_LoadBitmap(MAKE_IMAGE_PATH(TEXT("cannon.jpg")), &bitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL); 
   if (ret != SUCCESS) 
      return ret; 
 
   L_INT Width = bitmap.Width; 
   L_INT Height = bitmap.Height; 
 
   /* Apply manual perspective deskew filter to move down the top right corner by half of the image height*/ 
   L_ImgKrnPerspectiveCorrectionData data; 
   data.InputPoints[0].x = 0; 
   data.InputPoints[0].y = 0; 
   data.InputPoints[1].x = Width - 1; 
   data.InputPoints[1].y = 0; 
   data.InputPoints[2].x = 0; 
   data.InputPoints[2].y = Height - 1; 
   data.InputPoints[3].x = Width - 1; 
   data.InputPoints[3].y = Height - 1; 
 
   data.MappingPoints[0].x = 0; 
   data.MappingPoints[0].y = 0; 
   data.MappingPoints[1].x = Width - 1; 
   data.MappingPoints[1].y = Height / 2; 
   data.MappingPoints[2].x = 0; 
   data.MappingPoints[2].y = Height - 1; 
   data.MappingPoints[3].x = Width - 1; 
   data.MappingPoints[3].y = Height - 1; 
 
   ret = L_ImgKrnManualPerspectiveCorrection(&bitmap, &data, &resultBitmap, sizeof(BITMAPHANDLE)); 
   if (ret != SUCCESS) 
   { 
      ret = L_SaveBitmap(MAKE_IMAGE_PATH(TEXT("Result.BMP")), &resultBitmap, FILE_BMP, 24, 0, NULL); 
 
      L_FreeBitmap(&resultBitmap); 
   } 
 
   //free bitmap 
   L_FreeBitmap(&bitmap); 
 
   return ret; 
} 

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

LEADTOOLS Raster Imaging C API Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.