Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. import cv2
  2. import numpy as np
  3.  
  4. img_rgb = cv2.imread('opencv-template-matching-python-tutorial.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.  
  15. for pt in zip(*loc[::-1]):
  16. cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0,255,255), 2)
  17.  
  18. cv2.imshow('Detected',img_rgb)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement