ImageEn, unit ievision

TIEVisionImage.matchTemplate

TIEVisionImage.matchTemplate


Declaration

function matchTemplate(templ: TIEVisionImage; matchMethod: TIEVisionTemplateMatchMethod; rank: double_p = nil): TIEVisionRect; safecall;


Description

Search the image for the location of the template image and returns the best matched rectangle.

Parameter Description
templ Template image to find. It must be not larger than the source image
matchMethod Comparison method
rank Returns the confidence level of the match. Range is 0 to 100%, though generally values of <90% are not good matches



Using Template matching to find the original location of a cropped portion of image:



Note:
 To find multiple matches in an image, use matchTemplateMulti
 For a map of comparison results, use matchTemplateAsMap
 A shortcut method for this is available: MatchTemplate


Demos

Demo  Demos\IEVision\PatternMatching\PatternMatching.dpr
Demo  Demos\ImageEditing\EveryMethod\EveryMethod.dpr


Example

procedure TMainForm.Button2Click(Sender: TObject);
var
  image, templ: TIEVisionImage;
  rect: TIEVisionRect;
begin
  ImageEnView1.LayersClear( False );

  // get image to search
  image := ImageEnView1.IEBitmap.GetIEVisionImage();

  // get the template image to find
  templ := IEVSource.IEBitmap.GetIEVisionImage();

  // perform template searching
  rect := image.matchTemplate(templ, TIEVisionTemplateMatchMethod(ComboBox1.ItemIndex));

  // draw a red box around the found rectangle
  ImageEnView1.LayersAdd( iesRectangle, IEVisionRectToTRect( rect ), clRed, 2 );
end;