yamaji14

複数のオブジェクトを持つテンプレートマッチング

Nov 20th, 2014
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. import cv2
  2. import numpy as np
  3. from matplotlib import pyplot as plt
  4.  
  5. img_rgb = cv2.imread('gaikumerge_8bit.jpg')
  6. img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
  7. template = cv2.imread('kousi.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. for pt in zip(*loc[::-1]):
  14.     cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0,0,255), 2)
  15.  
  16. cv2.imwrite('resssss.png',img_rgb)
Advertisement
Add Comment
Please, Sign In to add comment