Skip to content

Commit 1cf135f

Browse files
committed
Add gluoncv display
1 parent 5147888 commit 1cf135f

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

test.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,32 @@
11
from skimage.data import coins
22
import matplotlib.pyplot as plt
33
import MTM, cv2
4+
import numpy as np
45

5-
## Get image and templates by cropping
6+
#%% Get image and templates by cropping
67
smallCoin = coins()[37:37+38, 80:80+41]
78
bigCoin = coins()[14:14+59,302:302+65]
89
image = 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

1415
print("Found {} coins".format(len(tableHit)))
15-
1616
print(tableHit)
1717

18-
19-
## Display matches
18+
#%% Display matches
2019
Overlay = MTM.drawBoxesOnRGB(image, tableHit, showLabel=True)
20+
plt.figure()
2121
plt.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

Comments
 (0)