Answer the question
In order to leave comments, you need to log in
How to make a loop that runs until a certain point?
There is the following function to search for an image in an image:
def find_img(template_path,sleep):
img_rgb = pyautogui.screenshot() # Скриншот текущего экрана
img_rgb.save('D:/images/general.jpg')
img_rgb = cv2.imread('D:/images/general.jpg') # Шаблон
template = cv2.imread(template_path) # Изображение, искомое в шаблоне
w, h = template.shape[:-1]
res = cv2.matchTemplate(img_rgb, template, cv2.TM_CCOEFF_NORMED)
if str(res[0]) != '[1. 1. 1. ... 1. 1. 1.]':
threshold = .7
loc = np.where(res >= threshold)
# Проверка совпадения
for pt in zip(*loc[::-1]):
x = int(pt[0])
y = int(pt[1])
print(x, y) # Координаты совпадения
pyautogui.moveTo(x, y, duration=0.7) # Переход по координатам
pyautogui.click()
time.sleep(sleep) #Ожидание sleep секунд.
break
else:
print('Image not found')
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question