D
D
Dmitry2017-09-09 14:51:55
Python
Dmitry, 2017-09-09 14:51:55

How to find a button on the screen and click on it?

Tell me how to find another image in Python 3.5 + OpenCV on the image and display if not then not if there is then save and circle the match and display that there is a match

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Kuts, 2017-09-09
@ipatov_dn

Sikuli
On OpenCV
Click on the button on the screen. Button image - in file 'butt01.png':

import cv2
import time
import numpy as np
import pyscreenshot as ImageGrab
import pyautogui


def find_patt(image, patt, thres):
  img_grey = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
  (patt_H, patt_W) = patt.shape[:2]
  res = cv2.matchTemplate(img_grey, patt, cv2.TM_CCOEFF_NORMED)
  loc = np.where(res>thres)
  return patt_H, patt_W, zip(*loc[::-1])


if __name__ == '__main__':
  screenshot = ImageGrab.grab()
  img = np.array(screenshot.getdata(), dtype='uint8').reshape((screenshot.size[1],screenshot.size[0],3)) 

  patt = cv2.imread('butt01.png', 0)
  h,w,points = find_patt(img, patt, 0.60)
  if len(points)!=0:
    pyautogui.moveTo(points[0][0]+w/2, points[0][1]+h/2)
    pyautogui.click()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question