GdPicture image identifier.
The left position, in pixel, (0-based), of the rectangle surrounding the template.
The top position, in pixel, (0-based), of the rectangle surrounding the template.
The width, in pixel, of the rectangle surrounding the template.
The height, in pixel, of the rectangle surrounding the template.
Example





In This Topic
GdPicture14 Namespace / GdPictureImaging Class / CreateAnchorTemplate Method

CreateAnchorTemplate Method (GdPictureImaging)

In This Topic
Creates an Anchor Template from a GdPicture image. Anchoring mechanism (or template recognition) can help to align area to be processed by filters, OMR, OCR or barcode recognition. For example, if several documents are scanned of the same form, and the scanning orientation or quality is not guaranteed, the GdPicture Anchoring System can be used to specify the orientation of each document and the translation made to each document from the one where the user selected their Areas (surrounding rectangles). Note: To maximize detection speed and accuracy, the Anchor region must contain less than 50% white pixel and should minimize white margins.
Syntax
'Declaration
 
Public Function CreateAnchorTemplate( _
   ByVal ImageID As Integer, _
   ByVal PosLeft As Integer, _
   ByVal PosTop As Integer, _
   ByVal Width As Integer, _
   ByVal Height As Integer _
) As IntPtr
public IntPtr CreateAnchorTemplate( 
   int ImageID,
   int PosLeft,
   int PosTop,
   int Width,
   int Height
)
public function CreateAnchorTemplate( 
    ImageID: Integer;
    PosLeft: Integer;
    PosTop: Integer;
    Width: Integer;
    Height: Integer
): IntPtr; 
public function CreateAnchorTemplate( 
   ImageID : int,
   PosLeft : int,
   PosTop : int,
   Width : int,
   Height : int
) : IntPtr;
public: IntPtr CreateAnchorTemplate( 
   int ImageID,
   int PosLeft,
   int PosTop,
   int Width,
   int Height
) 
public:
IntPtr CreateAnchorTemplate( 
   int ImageID,
   int PosLeft,
   int PosTop,
   int Width,
   int Height
) 

Parameters

ImageID
GdPicture image identifier.
PosLeft
The left position, in pixel, (0-based), of the rectangle surrounding the template.
PosTop
The top position, in pixel, (0-based), of the rectangle surrounding the template.
Width
The width, in pixel, of the rectangle surrounding the template.
Height
The height, in pixel, of the rectangle surrounding the template.

Return Value

An Anchor Template Identifier to be used with the FindAnchor and the DeleteAnchorTemplate method.
Remarks
This method is used in the "OMR" Demo. A result of 0 means that the method failed. Use the GetStat() method to determine if this method failed.

Be aware that FindAnchor() method ignores DPI. Templates and candidates need to have the same characteristics to achieve consistent results. That means you need to rescale images in question according to the DPI if required.

This method requires the ADR & OMR component to run.

Example
Creating an anchor template from the template image and finding the anchor element on the target image. The result is saved into a PNG file.
using (GdPictureImaging gdpictureImaging = new GdPictureImaging())
{
    // Open image files.
    int anchorImage = gdpictureImaging.CreateGdPictureImageFromFile("templateImage.tif");
    int targetImage = gdpictureImaging.CreateGdPictureImageFromFile("image.tif");
 
    // Create the anchor template. Let supose, that the key element is present on coordinates 100,100 and it has size 50 x 50 pixels.
    IntPtr template = gdpictureImaging.CreateAnchorTemplate(anchorImage, 100, 100, 50, 50);
 
    // Change the resolution of the target image to have the same dimensions (in pixels), as the template image.
    int anchorImgWidth = gdpictureImaging.GetWidth(anchorImage);
    int anchorImgHeight = gdpictureImaging.GetHeight(anchorImage);
    gdpictureImaging.Resize(targetImage, anchorImgWidth, anchorImgHeight, System.Drawing.Drawing2D.InterpolationMode.Default);
 
    int left = 0;
    int top = 0;
    int width = 0;
    int height = 0;
    double accuracy = 0;
    gdpictureImaging.FindAnchor(targetImage, template, OMRMode.FavorSpeed, 0, 0, anchorImgWidth, anchorImgHeight, ref left, ref top, ref width, ref height, ref accuracy);
 
    // If the anchor is successfully recognized, we will mark it on the target image.
    if (accuracy > 75)
    {
        gdpictureImaging.DrawRectangle(targetImage, left, top, width, height, 2, gdpictureImaging.ARGBI(255, 255, 0, 0), false);
    }
 
    gdpictureImaging.SaveAsPNG(targetImage, "output.png");
 
    // Release used resources.
    gdpictureImaging.ReleaseGdPictureImage(anchorImage);
    gdpictureImaging.ReleaseGdPictureImage(targetImage);
}
See Also