TIEVisionImage.matchTemplateMulti
Declaration
function matchTemplateMulti(templ: TIEVisionImage; templMask: TIEVisionImage; thresholdRank: double; out rects: TIEVisionVectorRect; out ranks: TIEVisionVectorDouble): int32_t; safecall;
Description
Search the image for the locations of the template image and returns the number of matches.
Parameter | Description |
templ | Template image to find. It must be not larger than the source image |
templMask | Pixels to use in template image (ie the template alpha mask). >0 use pixel |
thresholdRank | Minimum rank required. Range is 0 to 100%, though generally values of <90% are not good matches |
rects | Vector (list) of rectangles representing bounding boxes of found objects |
ranks | Vector (list) of doubles representing ranks found objects |
Note:
◼If only a single result is required, use
matchTemplate◼For a map of comparison results, use
matchTemplateAsMap◼A shortcut method for this is available:
MatchTemplate | Demos\IEVision\PatternMatchingMulti\PatternMatchingMulti.dpr |
| Demos\ImageEditing\EveryMethod\EveryMethod.dpr |
var
image, templ, templMask: TIEVisionImage;
rects: TIEVisionVectorRect;
ranks: TIEVisionVectorDouble;
i, count: Integer;
begin
// get image where to search in (from ImageEnView1)
image := ImageEnView1.IEBitmap.GetIEVisionImage();
// get the template image to search (from ImageEnView2)
templ := ImageEnView2.IEBitmap.GetIEVisionImage();
// get template mask (from alpha channel)
if ImageEnView2.IEBitmap.HasAlphaChannel() then
templMask := ImageEnView2.IEBitmap.AlphaChannel.GetIEVisionImage(true)
else
templMask := nil;
// perform template searching
count := image.matchTemplateMulti(templ, templMask, 95, rects, ranks);
for i := 0 to count - 1 do
begin
// draw a red box around the found rectangle
ImageEnView1.LayersAdd( ielkText, IEVisionRectToTRect( rects.getRect(i) ));
with TIETextLayer( ImageEnView1.CurrentLayer ) do
begin
BorderColor := clRed;
BorderWidth := 2;
FillColor := clWhite;
Opacity := 0.66;
Font.Height := 24;
Font.Color := clRed;
WordWrap := False;
Alignment := iejCenter;
Text := '#' + IntToStr(i + 1) + ' ' + FloatToStr(trunc(ranks.getDouble(i))) + '%';
TextOverflow := ieoShrink;
end;
end;
end;