Created
August 25, 2020 01:12
-
-
Save wonsolution/732b4b97db4dbf8b834506336697c6ee to your computer and use it in GitHub Desktop.
color recognition macro
This file contains 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
-------------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