Last active
          January 3, 2021 21:49 
        
      - 
      
- 
        Save vitorvargasdev/70d36211b789ed0893c676e8e208bc1d to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import cv2 | |
| import pyautogui | |
| import numpy as np | |
| def search(image): | |
| # Tira print da tela e salva a imagem | |
| img_rgb = pyautogui.screenshot() | |
| img_rgb = np.array(img_rgb) | |
| img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY) | |
| cv2.imwrite("screenshot.png", img_gray) | |
| img = cv2.imread("screenshot.png") | |
| # Pega a marcacao selecionada | |
| template = cv2.imread(image, 0) | |
| cinza = np.all(img == [120, 120, 120], axis=- 1) | |
| cinza2 = np.all(img == [153, 153, 153], axis=- 1) | |
| cinza3 = np.all(img == [60, 60, 60], axis=- 1) | |
| cinza4 = np.all(img == [93, 93, 93], axis=- 1) | |
| cinza5 = np.all(img == [82, 82, 82], axis=- 1) | |
| cinza6 = np.all(img == [67, 67, 67], axis=- 1) | |
| cinza7 = np.all(img == [118, 118, 118], axis=- 1) | |
| cinza8 = np.all(img == [102, 102, 102], axis=- 1) | |
| cinza9 = np.all(img == [86, 86, 86], axis=- 1) | |
| cinza10 = np.all(img == [56, 56, 56], axis=- 1) | |
| cinza11 = np.all(img == [117, 117, 117], axis=- 1) | |
| cinza12 = np.all(img == [95, 95, 95], axis=- 1) | |
| cinza13 = np.all(img == [119, 119, 119], axis=- 1) | |
| cinza14 = np.all(img == [152, 152, 152], axis=- 1) | |
| cinza15 = np.all(img == [101, 101, 101], axis=- 1) | |
| img[cinza | cinza2 | cinza3 | cinza4 | cinza5 | cinza6 | cinza7 | cinza8 | cinza9 | cinza10 | cinza11 | cinza12 | cinza13 | cinza14 | cinza15] = [000, 000, 000] | |
| test1 = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) | |
| # cv2.imshow('dsadasd', test1) | |
| # cv2.waitKey(0) | |
| res = cv2.matchTemplate(test1, template, cv2.TM_CCOEFF_NORMED) | |
| min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res) | |
| if max_val < 0.8: | |
| return [-1, -1] | |
| return max_loc | |
| pos = search('mark3.png') | |
| print(pos) | |
| pyautogui.moveTo(pos[0], pos[1]) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment