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 (usually this is AlphaChannel) |
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
Template Mask
It is recommended that you specify a template mask (i.e. by providing the alpha channel of the image), this prevents the background from being included in the object identification (e.g. if you pass an image with a lot of white background, it will match with any white in the image).
If your image does not have an alpha channel, you might want to remove the background using
SetTransparentColors, e.g.
ImageEnMView1.GetTIEBitmap(idx).SetTransparentColors( CreateRGB(255, 255, 255), 12, 0 );
templMask := ImageEnMView1.GetTIEBitmap(idx).AlphaChannel.GetIEVisionImage(true);
| 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 to search in (from ImageEnView1)
image := ImageEnView1.IEBitmap.GetIEVisionImage();
// Get the template image that we want to find (from ImageEnView2)
templ := ImageEnView2.IEBitmap.GetIEVisionImage();
// Get the template mask (to exclude the alpha channel)
if ImageEnView2.IEBitmap.HasAlphaChannel() then
templMask := ImageEnView2.IEBitmap.AlphaChannel.GetIEVisionImage(true)
else
templMask := nil;
// Perform the template search
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;