Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def search(path, coordinates, match, box):
- img_rgb = pyautogui.screenshot() # Скриншот текущего экрана
- img_rgb.save('D:/images/general.png')
- img_rgb = img_rgb.crop(box)
- img_rgb = cv2.imread('D:/images/general.png') # Шаблон
- template = cv2.imread(path) # Изображение, искомое в шаблоне
- res = cv2.matchTemplate(img_rgb, template, cv2.TM_CCOEFF_NORMED)
- if str(res[0]) != '[1. 1. 1. ... 1. 1. 1.]':
- threshold = match #match 0.1 - 0.99
- loc = np.where(res >= threshold)
- # Проверка совпадения
- for pt in zip(*loc[::-1]):
- x = int(pt[0])
- y = int(pt[1])
- value = True
- if coordinates == True:
- print('Image found, coordinates: {}, {}'.format(x,y)) # Координаты совпадения
- print('Transition by coordinates ...')
- pyautogui.moveTo(x, y, duration=0.5) # Переход по координатам
- pyautogui.click()
- else:
- print('Image found ')
- break
- else:
- value = False
- print('Image not found')
- return value
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement