try
{
IplImage tpl = Cv.LoadImage("template path", LoadMode.Color);
IplImage img = Cv.LoadImage("main image path", LoadMode.Color);
IplImage res = Cv.CreateImage(Cv.Size(img.Width - tpl.Width + 1, img.Height - tpl.Height + 1), BitDepth.F32, 1);
Cv.MatchTemplate(img, tpl, res, MatchTemplateMethod.CCoeffNormed);
Cv.Threshold(res, res, 0.9, 255, ThresholdType.ToZero);
while (true)
{
CvPoint minloc, maxloc;
double minval, maxval, threshold = 0.95;
Cv.MinMaxLoc(res, out minval, out maxval, out minloc, out maxloc, null);
if (maxval > threshold)
{
Console.WriteLine("Matched " + maxloc.X + "," + maxloc.Y);
Cv.FloodFill(res, maxloc, new CvScalar());
}
else
{
Console.WriteLine("No More Matches");
break;
}
}
Cv.ReleaseImage(res);
Cv.ReleaseImage(img);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}