Advertisement
Mr_D3a1h

Untitled

Mar 10th, 2023
826
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.73 KB | None | 0 0
  1. import cv2
  2. import numpy as n
  3. import imutils
  4.  
  5. img_rgb = cv2.imread('/Users/macbook/Downloads/e447a0c9-876b-431b-9c0f-abba6aa88c45.png')
  6. template = cv2.imread('/Users/macbook/Downloads/Waldo.png')
  7. w, h = template.shape[:-1]
  8.  
  9. res = cv2.matchTemplate(img_rgb, template, cv2.TM_CCOEFF_NORMED)
  10. threshold = .8
  11. loc = n.where(res >= threshold)
  12. for pt in zip(*loc[::-1]): # Switch columns and rows
  13.     cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0, 0, 255), 2)
  14. mask = n.zeros(img_rgb.shape, dtype = "uint8")
  15. img_rgb[cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0, 0, 255), 2)]
  16. #img_rgb = cv2.addWeighted(img_rgb, 0.3, mask, 0.7, 0)
  17. #cv2.imwrite("result.png"Iutils.resize(img_rgb, height = 650))
  18. cv2.imwrite('result.png', img_rgb)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement