简体   繁体   中英

Finding specific RGB color and auto clicking on it with pyautogui

Im working on my first "real" project for python. It automates a click accuracy test. The goal is to find the red circles and automatically locate and click on it.

Im currently using pyautogui to take a screenshot, but im stuck on how to auto locate the RGB color I need.

def find_red_dot():
    print('STARTED TEST!')
    time.sleep(5)
    image = pyautogui.screenshot()
    pyautogui.pixelMatchesColor(# Find the color)
    print('FOUND THE RED DOT')

def click_on_dot():
    pyautogui.moveTo(# Location where the color is found)
    pyautogui.click()

Cant seem to figure out how to get pyautogui to find the rgb color, (255,0,58)

我有一种方法,它不是很好,但也许您可以尝试:通过使用所需颜色制作一张1像素的图片,并使用该图片pyautogui.locateallonscreen() ,pyautogui将为该单色图片搜索每个像素。表示颜色。

Old post but this will work;

import pyautogui as py
py.displayMousePosition()

Run in your IDE and it'll display in the terminal the screen position and the RGB value of any pixel.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM