Advertisement
Guest User

def cropped

a guest
Dec 16th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.24 KB | None | 0 0
  1. def search(path, coordinates, match, box):
  2.     img_rgb = pyautogui.screenshot() # Скриншот текущего экрана
  3.     img_rgb.save('D:/images/general.png')  
  4.     img_rgb = img_rgb.crop(box)
  5.     img_rgb = cv2.imread('D:/images/general.png') # Шаблон
  6.  
  7.     template = cv2.imread(path)  # Изображение, искомое в шаблоне
  8.  
  9.     res = cv2.matchTemplate(img_rgb, template, cv2.TM_CCOEFF_NORMED)
  10.  
  11.     if str(res[0]) != '[1. 1. 1. ... 1. 1. 1.]':
  12.         threshold = match  #match 0.1 - 0.99
  13.  
  14.         loc = np.where(res >= threshold)  
  15.         # Проверка совпадения
  16.         for pt in zip(*loc[::-1]):
  17.             x = int(pt[0])
  18.             y = int(pt[1])
  19.             value = True
  20.             if coordinates == True:
  21.                 print('Image found, coordinates: {}, {}'.format(x,y)) # Координаты совпадения
  22.                 print('Transition by coordinates ...')
  23.                 pyautogui.moveTo(x, y, duration=0.5)  # Переход по координатам
  24.                 pyautogui.click()
  25.             else:
  26.                 print('Image found ')
  27.             break
  28.         else:
  29.             value = False
  30.             print('Image not found')
  31.     return value
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement