FormFix v6.0 for .NET - Updated
GetAffineTransformation Method
Example 



Accusoft.FormFixSdk Namespace > RegistrationResult Class : GetAffineTransformation Method
Creates a 3x3 affine transformation matrix that represents the alignment information contained within the RegistrationResult.
Syntax
'Declaration
 
Public Function GetAffineTransformation() As Matrix
'Usage
 
Dim instance As RegistrationResult
Dim value As Matrix
 
value = instance.GetAffineTransformation()
public Matrix GetAffineTransformation()
public:
Matrix^ GetAffineTransformation(); 

Return Value

An affine transformation matrix that represents the alignment transformation information stored within the RegistrationResult. This transformation matrix represents the mapping from the coordinate system of the unaligned image, to the coordinate system of the model (template) image.If the State of the RegistrationResult is equal to RegistrationState.Failure, the value of the returned matrix is not guaranteed.
Remarks

The returned transformation matrix represents the transformation from the coordinate system of the unaligned image into the coordinate system of the model (template) image. The origin of each of the coordinate systems is the top left corner of the image.

Inverting the Transformation

To get a matrix representing the mapping from the coordinate system of the model image to the coordinate system of the filled image, you must compute the inverse of the transformation matrix. To compute the inverse of this transformation, use the System.Drawing.Drawing2D.Matrix.Inverse() method. This will modify the transformation matrix so that it represents the transformation from the coordinate system of the template image to the coordinate system of the unaligned image.

Using the Transformation to Compute Field Locations in the Filled Image

To compute the location of a field (as defined by a set of four points) in the unaligned image, first compute the inverse of the affine transformation matrix. Then use the System.Drawing.Drawing2D.Matrix.TransformPoints(Point[] points) method to apply the transform to an array of points.

Example
This sample shows how to call GetAffineTransformation and then use the returned Matrix to compute the location of a field in the unaligned form image, based on coordinates of the field in the template image.
// generate the affine transformation
System.Drawing.Drawing2D.Matrix affineTransform =
     myRegistrationResult.GetAffineTransformation();
     
// invert the transformation so that it represents the
// mapping from the template image to the filled image
affineTransform.Invert();
                   
// define a field within the template image
System.Drawing.Rectangle myField = new System.Drawing.Rectangle(10, 10, 200, 50);
            
// Get points that represent the corners of the field
System.Drawing.Point topLeft, topRight, bottomLeft, bottomRight;
topLeft = new System.Drawing.Point(myField.Left, myField.Top);
topRight = new System.Drawing.Point(myField.Right, myField.Top);
bottomLeft = new System.Drawing.Point(myField.Left, myField.Bottom);
bottomRight = new System.Drawing.Point(myField.Right, myField.Bottom);
            
// create array of the points
System.Drawing.Point[] cornersOfField = 
     new System.Drawing.Point[] { topLeft, topRight, bottomLeft, bottomRight };
            
// map the points into the filled image
affineTransform.TransformPoints(cornersOfField);
            
// use the transformed points
int newXTopLeft = cornersOfField[0].X;
int newYTopLeft = cornersOfField[0].Y;
See Also

Reference

RegistrationResult Class
RegistrationResult Members

Is this page helpful?
Yes No
Thanks for your feedback.