Skip to content

Commit c73f7ed

Browse files
committed
add MatchTemplate test
1 parent 3acb3e6 commit c73f7ed

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

test/OpenCvSharp.Tests/imgproc/ImgProcTest.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,33 @@ public void CalcHist()
583583
Window.ShowImages(src, histImage);
584584
}
585585
}
586+
587+
[Fact]
588+
public void MatchTemplate()
589+
{
590+
using var src = new Mat("_data/image/qr_multi.png", ImreadModes.Grayscale);
591+
using var template = src[new Rect(33, 33, 235, 235)];
592+
593+
using var result = new Mat();
594+
Cv2.MatchTemplate(src, template, result, TemplateMatchModes.CCoeffNormed);
595+
596+
Assert.False(result.Empty());
597+
Assert.Equal(MatType.CV_32FC1, result.Type());
598+
Assert.Equal(src.Rows - template.Rows + 1, result.Rows);
599+
Assert.Equal(src.Cols - template.Cols + 1, result.Cols);
600+
601+
Cv2.MinMaxLoc(result, out _, out Point maxLoc);
602+
Assert.Equal(new Point(33, 33), maxLoc);
603+
604+
if (Debugger.IsAttached)
605+
{
606+
using var view = new Mat();
607+
Cv2.CvtColor(src, view, ColorConversionCodes.GRAY2BGR);
608+
Cv2.Rectangle(view, new Rect(maxLoc, template.Size()), Scalar.Red, 2);
609+
610+
Window.ShowImages(view, result);
611+
}
612+
}
586613
}
587614
}
588615

0 commit comments

Comments
 (0)