@@ -583,6 +583,33 @@ public void CalcHist()
583
583
Window . ShowImages ( src , histImage ) ;
584
584
}
585
585
}
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
+ }
586
613
}
587
614
}
588
615
0 commit comments