Products | Support | Send comments on this topic. | Email a link to this topic. | Back to Getting Started | Help Version 18.0.11.1
LEADTOOLS Raster Imaging C DLL Help

L_GetTransformationParameters

Show in webframe

#include "l_bitmap.h"

L_LTIMGCOR_API L_INT L_GetTransformationParameters (pBitmap, pRefPoints, pTrnsPoints, pnXTranslation, pnYTranslation,pnAngle, puXScale, puYScale, uFlags)

pBITMAPHANDLE pBitmap;

/* pointer to the bitmap handle */

POINT *pRefPoints;

/* pointer to an array of reference points */

POINT *pTrnsPoints;

/* pointer to an array of transformed points */

L_INT *pnXTranslation;

/* pointer to a variable to be updated */

L_INT *pnYTranslation;

/* pointer to a variable to be updated */

L_INT *pnAngle;

/* pointer to a variable to be updated */

L_UINT *puXScale;

/* pointer to a variable to be updated */

L_UINT *puYScale;

/* pointer to a variable to be updated */

L_UINT32 uFlags;

/* flags */

Computes the rotation angle, XY scaling, and XY translation of the transformed bitmap with comparison to the reference bitmap. These are the transformations that would have to be performed to the reference bitmap to have it match the current bitmap.

Parameter

Description

pBitmap

Pointer to the bitmap handle referencing the transformed bitmap.

pRefPoints

Pointer to an array of reference points. These points represent the center of mass points for the registration in the reference bitmap. You have to provide this information.

pTrnsPoints

Pointer to an array of transformed points. These points are the center of mass points in pBitmap. You have to provide this information.

pnXTranslation

Pointer to a variable to be updated by the bitmap x-translation, in hundredths of pixels.

pnYTranslation

Pointer to a variable to be updated by the bitmap y-translation, in hundredths of pixels.

pnAngle

Pointer to a variable to be updated with the bitmap rotation angle, in hundredths of degrees.

puXScale

Pointer to a variable to be updated with the bitmap x-scaling (resizing), in percent.

puYScale

Pointer to a variable to be updated with the bitmap y-scaling (resizing), in percent.

uFlags

Reserved for future use. Must be 0.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

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 detects transformation parameters of the transformed bitmap by comparing it with the reference bitmap. The number of reference and detected points must be three.

Use L_GetMarksCenterMassBitmap to fill the pRefPoints array with the points representing the center of masses for each of the reference marks from the reference bitmap.

Fill the pTrnsPoints array by peforming the following steps:

Use L_SearchRegMarksBitmap to find the new positions for the reference marks

Using L_GetMarksCenterMassBitmap to fill the pTrnsPoint array with points representing the center of masses for each of the transformed reference marks.

The values pnXTranslation, pnYTranslation, pnAngle, puXScale and puYScale are internally divided by 100. For example, a pnAngle of 500 would mean to rotate the bitmap 5 degrees clockwise.

The results of this function must be sent without any modification to the L_ApplyTransformationParameters function in order to correct the image.

If you want to correct the image yourself, you have to perform the inverse operations in this order:

1.

Shift the image by (-*pXTranslation / 100, -*pYTranslation / 100) using L_CombineBitmap

2.

Rotate without resizing by (*pnAngle)

3.

Resize using scaling factors of (100 / *puXScale, 100 / *puYScale) using L_SizeBitmap or L_ResizeBitmap

This function does not use L_SetStatusCallback.

If you simply want to automatically straighten a bitmap, use the L_DeskewBitmap function.

This function supports 12 and 16-bit grayscale and 48 and 64-bit color images. Support for 12 and 16-bit grayscale and 48 and 64-bit color images is available in the Document and Medical Imaging toolkits.

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.

Required DLLs and Libraries

LTIMGCOR

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

Platforms

Win32, x64, Linux.

See Also

Functions:

L_CombineBitmap, L_RotateBitmap, L_SizeBitmap, L_ResizeBitmap, L_IsRegMarkBitmap, L_SearchRegMarksBitmap, L_GetMarksCenterMassBitmap, L_SizeBitmapInterpolate, L_AutoZoneBitmap

Topics:

Raster Image Functions: Document Imaging

 

Detecting Registration Marks

Example

#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName


#if defined (LEADTOOLS_V16_OR_LATER)
L_INT GetTransformationParametersExample(L_VOID)
{
   L_INT nRet;
   BITMAPHANDLE LeadBitmap;   // Bitmap handle for the image 
   L_INT nAngle; 
   L_UINT  uXScale, uYScale ;
   L_INT   nXTranslation,nYTranslation; 
   SEARCHMARKS aSearchMarks[3]; 
   POINT  aMarkPoints[3]; 
   POINT  aMarkCMPoints[3]; 
   POINT aRefPoints[3]; 
   POINT CenterPt; 
 
   // Load a bitmap at its own bits per pixel 
   nRet = L_LoadBitmap (MAKE_IMAGE_PATH(TEXT("RGSRef.cmp")), &LeadBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL); 
 
   if(nRet !=SUCCESS)
      return nRet;
 
   // bend the image around it is center 
   CenterPt.x  =  LeadBitmap.Width/2; 
   CenterPt.y  =  LeadBitmap.Height/2; 
 
   /* Get aRefPoints from pre-calculated saved values.*/
   aRefPoints[0].x = 80600; 
   aRefPoints[0].y = 11400; 
   aRefPoints[1].x = 78700; 
   aRefPoints[1].y = 116100; 
   aRefPoints[2].x = 13600; 
   aRefPoints[2].y = 115500; 
 
   /*Get registration marks CM*/
 
   aSearchMarks->uStructSize =sizeof(SEARCHMARKS);
 
   aSearchMarks[0].uType = RGS_T; 
   aSearchMarks[0].uMinScale = 90; 
   aSearchMarks[0].uMaxScale = 110; 
   aSearchMarks[0].uWidth = 31; 
   aSearchMarks[0].uHeight = 29; 
   SetRect(&aSearchMarks[0].rcRect, 700,80,900,150); 
   aSearchMarks[0].uSearchMarkCount = 1; 
   aSearchMarks[0].pMarkDetectedPoints = (POINT  *) malloc(aSearchMarks[0].uSearchMarkCount * sizeof(POINT)); 
 
   aSearchMarks[1].uType = RGS_T; 
   aSearchMarks[1].uMinScale = 90; 
   aSearchMarks[1].uMaxScale = 110; 
   aSearchMarks[1].uWidth = 31; 
   aSearchMarks[1].uHeight = 29; 
   SetRect(&aSearchMarks[1].rcRect,700,900,900,1250); 
   aSearchMarks[1].uSearchMarkCount = 1; 
   aSearchMarks[1].pMarkDetectedPoints = (POINT *) malloc(aSearchMarks[1].uSearchMarkCount * sizeof(POINT)); 
 
   aSearchMarks[2].uType = RGS_T; 
   aSearchMarks[2].uMinScale = 90; 
   aSearchMarks[2].uMaxScale = 110; 
   aSearchMarks[2].uWidth = 31; 
   aSearchMarks[2].uHeight = 29; 
   SetRect(&aSearchMarks[2].rcRect,100,1100,200,1250); 
   aSearchMarks[2].uSearchMarkCount = 1; 
   aSearchMarks[2].pMarkDetectedPoints = (POINT  *)malloc(aSearchMarks[2].uSearchMarkCount * sizeof(POINT)); 
 
   nRet = L_LoadBitmap (MAKE_IMAGE_PATH(TEXT("RGSTest.cmp")), &LeadBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL); 
   if(nRet !=SUCCESS)
      return nRet;
 
 
   nRet = L_SearchRegMarksBitmap (&LeadBitmap,aSearchMarks,3, 0); 
   if(nRet !=SUCCESS)
      return nRet;
 
   aMarkPoints[0]= *aSearchMarks[0].pMarkDetectedPoints; 
   aMarkPoints[1]= *aSearchMarks[1].pMarkDetectedPoints; 
   aMarkPoints[2]= *aSearchMarks[2].pMarkDetectedPoints; 
 
   free(aSearchMarks[0].pMarkDetectedPoints); 
   free(aSearchMarks[1].pMarkDetectedPoints); 
   free(aSearchMarks[2].pMarkDetectedPoints); 
 
   nRet = L_GetMarksCenterMassBitmap (&LeadBitmap, aMarkPoints, aMarkCMPoints, 3, 0); 
   if(nRet !=SUCCESS)
      return nRet;
 
 
   nRet = L_GetTransformationParameters (&LeadBitmap, aRefPoints, aMarkCMPoints, &nXTranslation, &nYTranslation, &nAngle, &uXScale, &uYScale, 0); 
   if(nRet !=SUCCESS)
      return nRet;
 
 
   nRet = L_ApplyTransformationParameters (&LeadBitmap, nXTranslation, nYTranslation,nAngle,  uXScale, uYScale, RGS_SIZE_BICUBIC); 
   if(nRet !=SUCCESS)
      return nRet;
   nRet = L_SaveBitmap(MAKE_IMAGE_PATH(TEXT("Result.BMP")), &LeadBitmap, FILE_BMP, 24, 0, NULL);
   if(nRet !=SUCCESS)
      return nRet;
   //free bitmap 
   if(LeadBitmap.Flags.Allocated)  
      L_FreeBitmap(&LeadBitmap);  
   return SUCCESS;
}

#else
L_INT GetTransformationParametersExample(L_VOID)
{
   L_INT nRet;
   BITMAPHANDLE LeadBitmap;   // Bitmap handle for the image 
   L_INT nAngle; 
   L_UINT  uXScale, uYScale ;
   L_INT   nXTranslation,nYTranslation; 
   SEARCHMARKS aSearchMarks[3]; 
   POINT  aMarkPoints[3]; 
   POINT  aMarkCMPoints[3]; 
   POINT aRefPoints[3]; 
   POINT CenterPt; 
 
   // Load a bitmap at its own bits per pixel 
   nRet = L_LoadBitmap (MAKE_IMAGE_PATH(TEXT("RGSRef.cmp")), &LeadBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL); 
 
   if(nRet !=SUCCESS)
      return nRet;
 
   // bend the image around it is center 
   CenterPt.x  =  LeadBitmap.Width/2; 
   CenterPt.y  =  LeadBitmap.Height/2; 
 
   /* Get aRefPoints from pre-calculated saved values.*/
   aRefPoints[0].x = 80600; 
   aRefPoints[0].y = 11400; 
   aRefPoints[1].x = 78700; 
   aRefPoints[1].y = 116100; 
   aRefPoints[2].x = 13600; 
   aRefPoints[2].y = 115500; 
 
   /*Get registration marks CM*/
 
   aSearchMarks->uStructSize =sizeof(SEARCHMARKS);
 
   aSearchMarks[0].uType = RGS_T; 
   aSearchMarks[0].uMinScale = 90; 
   aSearchMarks[0].uMaxScale = 110; 
   aSearchMarks[0].uWidth = 31; 
   aSearchMarks[0].uHeight = 29; 
   SetRect(&aSearchMarks[0].rcRect, 700,80,900,150); 
   aSearchMarks[0].uSearchMarkCount = 1; 
   aSearchMarks[0].pMarkDetectedPoints = (POINT  *) malloc(aSearchMarks[0].uSearchMarkCount * sizeof(POINT)); 
 
   aSearchMarks[1].uType = RGS_T; 
   aSearchMarks[1].uMinScale = 90; 
   aSearchMarks[1].uMaxScale = 110; 
   aSearchMarks[1].uWidth = 31; 
   aSearchMarks[1].uHeight = 29; 
   SetRect(&aSearchMarks[1].rcRect,700,900,900,1250); 
   aSearchMarks[1].uSearchMarkCount = 1; 
   aSearchMarks[1].pMarkDetectedPoints = (POINT *) malloc(aSearchMarks[1].uSearchMarkCount * sizeof(POINT)); 
 
   aSearchMarks[2].uType = RGS_T; 
   aSearchMarks[2].uMinScale = 90; 
   aSearchMarks[2].uMaxScale = 110; 
   aSearchMarks[2].uWidth = 31; 
   aSearchMarks[2].uHeight = 29; 
   SetRect(&aSearchMarks[2].rcRect,100,1100,200,1250); 
   aSearchMarks[2].uSearchMarkCount = 1; 
   aSearchMarks[2].pMarkDetectedPoints = (POINT  *)malloc(aSearchMarks[2].uSearchMarkCount * sizeof(POINT)); 
 
   nRet = L_LoadBitmap (MAKE_IMAGE_PATH(TEXT("RGSTest.cmp")), &LeadBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL); 
   if(nRet !=SUCCESS)
      return nRet;
 
 
   nRet = L_SearchRegMarksBitmap (&LeadBitmap,aSearchMarks,3); 
   if(nRet !=SUCCESS)
      return nRet;
 
   aMarkPoints[0]= *aSearchMarks[0].pMarkDetectedPoints; 
   aMarkPoints[1]= *aSearchMarks[1].pMarkDetectedPoints; 
   aMarkPoints[2]= *aSearchMarks[2].pMarkDetectedPoints; 
 
   free(aSearchMarks[0].pMarkDetectedPoints); 
   free(aSearchMarks[1].pMarkDetectedPoints); 
   free(aSearchMarks[2].pMarkDetectedPoints); 
 
   nRet = L_GetMarksCenterMassBitmap (&LeadBitmap, aMarkPoints, aMarkCMPoints, 3); 
   if(nRet !=SUCCESS)
      return nRet;
 
 
   nRet = L_GetTransformationParameters (&LeadBitmap, aRefPoints, aMarkCMPoints, &nXTranslation, &nYTranslation, &nAngle, &uXScale, &uYScale); 
   if(nRet !=SUCCESS)
      return nRet;
 
 
   nRet = L_ApplyTransformationParameters (&LeadBitmap, nXTranslation, nYTranslation,nAngle,  uXScale, uYScale, RGS_SIZE_BICUBIC); 
   if(nRet !=SUCCESS)
      return nRet;
   nRet = L_SaveBitmap(MAKE_IMAGE_PATH(TEXT("Result.BMP")), &LeadBitmap, FILE_BMP, 24, 0, NULL);
   if(nRet !=SUCCESS)
      return nRet;
   //free bitmap 
   if(LeadBitmap.Flags.Allocated)  
      L_FreeBitmap(&LeadBitmap);  
   return SUCCESS;
}

#endif // LEADTOOLS_V16_OR_LATER
Products | Support | Contact Us | Copyright Notices
© 2006-2014 All Rights Reserved. LEAD Technologies, Inc.