Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. import cv2
  2. import numpy as np
  3.  
  4. img_rgb = cv2.imread('big_img.png') # https://prnt.sc/pw2ltm
  5. template = cv2.imread('small_img.png') # https://prnt.sc/pw2m9t
  6. #template = cv2.imread('img2.png') # картинка которой нет в img_rbg
  7. w, h = template.shape[:-1]
  8.  
  9. res = cv2.matchTemplate(img_rgb, template, cv2.TM_CCOEFF_NORMED)
  10.  
  11. # проверка нахождения
  12. if str(res[0]) != '[1. 1. 1. ... 1. 1. 1.]':
  13.     threshold = .8
  14.  
  15.     loc = np.where(res >= threshold)  
  16.    
  17.     for pt in zip(*loc[::-1]):
  18.         x = int(pt[0])
  19.         y = int(pt[1])
  20.         print(x, y) # координаты совпадения    
  21.    
  22. else:
  23.     print('совпадений не найдено')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement