Skip to content

Commit fe63d88

Browse files
committed
Template matching
1 parent 042df70 commit fe63d88

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

opencv-template-for-matching.jpg

988 Bytes
Loading

opencv-template-matching.jpg

176 KB
Loading

src12.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import cv2
2+
import numpy as np
3+
4+
img_rgb = cv2.imread('opencv-template-matching.jpg')
5+
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
6+
7+
template = cv2.imread('opencv-template-for-matching.jpg',0)
8+
w, h = template.shape[::-1]
9+
10+
res = cv2.matchTemplate(img_gray,template,cv2.TM_CCOEFF_NORMED)
11+
threshold = 0.8
12+
loc = np.where( res >= threshold)
13+
14+
for pt in zip(*loc[::-1]):
15+
cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0,255,255), 2)
16+
17+
cv2.imshow('Detected',img_rgb)
18+
cv2.waitKey(0)
19+
cv2.destroyAllWindows()

0 commit comments

Comments
 (0)