Skip to content

Instantly share code, notes, and snippets.

@wonsolution
Created August 25, 2020 01:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wonsolution/732b4b97db4dbf8b834506336697c6ee to your computer and use it in GitHub Desktop.
Save wonsolution/732b4b97db4dbf8b834506336697c6ee to your computer and use it in GitHub Desktop.
color recognition macro
-------------pyautogui이용(screenShot)
def rgbColor():
black=(0, 0, 0)
red=(237, 28, 36)
green=(34, 177, 76)
blue=(63, 72, 204)
white=(255, 255, 255)
scr = ag.screenshot()
mpos = ag.position()
print(mpos)
rgb = scr.getpixel(mpos)
if rgb == black : print('검정')
elif rgb == red : print('빨강')
elif rgb == green : print('초록')
elif rgb == blue : print('파랑')
elif rgb == white : print('하양')
else : print ('아무색')
rgbColor()
----------------pillow이용(from PIL import Image)
import pyautogui as ag
from PIL import Image
black=(0, 0, 0)
red=(237, 28, 36)
green=(34, 177, 76)
blue=(63, 72, 204)
white=(255, 255, 255)
scr = ImageGrab.grab()
mpos = ag.position()
print(mpos)
rgb = scr.getpixel(mpos)
if rgb == black : print('검정')
elif rgb == red : print('빨강')
elif rgb == green : print('초록')
elif rgb == blue : print('파랑')
elif rgb == white : print('하양')
else : print ('아무색')
------------------------------------------------------------------------------
단축키
while 1:
while 1:
if keyboard.is_pressed('F3'):
mpos = ag.position()
pixel = scr.getpixel(mpos)
print(mpos,pixel)
break
while True:
if keyboard.is_pressed('F4'):
print('F4')
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment