11from skimage .data import coins
22import matplotlib .pyplot as plt
33import MTM , cv2
4+ import numpy as np
45
5- ## Get image and templates by cropping
6+ #%% Get image and templates by cropping
67smallCoin = coins ()[37 :37 + 38 , 80 :80 + 41 ]
78bigCoin = coins ()[14 :14 + 59 ,302 :302 + 65 ]
89image = coins ()
910
10- ## Perform matching
11- # tableHit = MTM.matchTemplates([('small', smallCoin), ('big', bigCoin)], image, score_threshold=0.6, method=cv2.TM_CCOEFF_NORMED, maxOverlap=0) # Correlation-score
12- tableHit = MTM .matchTemplates ([('small' , smallCoin ), ('big' , bigCoin )], image , score_threshold = 0.4 , method = cv2 .TM_SQDIFF_NORMED , maxOverlap = 0 ) # Difference-score
11+ #%% Perform matching
12+ tableHit = MTM .matchTemplates ([('small' , smallCoin ), ('big' , bigCoin )], image , score_threshold = 0.6 , method = cv2 .TM_CCOEFF_NORMED , maxOverlap = 0 ) # Correlation-score
13+ # tableHit = MTM.matchTemplates([('small', smallCoin), ('big', bigCoin)], image, score_threshold=0.4, method=cv2.TM_SQDIFF_NORMED, maxOverlap=0) # Difference-score
1314
1415print ("Found {} coins" .format (len (tableHit )))
15-
1616print (tableHit )
1717
18-
19- ## Display matches
18+ #%% Display matches
2019Overlay = MTM .drawBoxesOnRGB (image , tableHit , showLabel = True )
20+ plt .figure ()
2121plt .imshow (Overlay )
22+
23+ #%% Use GluonCV for display
24+ import gluoncv as gcv
25+
26+ # Convert from x,y,w,h to xmin, ymin, xmax, ymax
27+ BBoxes_xywh = np .array ( tableHit ["BBox" ].tolist () )
28+ BBoxes_xyxy = gcv .utils .bbox .bbox_xywh_to_xyxy (BBoxes_xywh )
29+
30+ Overlay2 = gcv .utils .viz .cv_plot_bbox (cv2 .cvtColor (image , cv2 .COLOR_GRAY2RGB ), BBoxes_xyxy .astype ("float64" ), scores = tableHit ["Score" ].to_numpy (), thresh = 0 )
31+ plt .figure ()
32+ plt .imshow (Overlay2 )
0 commit comments