Python
파이썬 화면 픽셀 RGB 구하기
ndlessrain
2023. 6. 5. 15:45
728x90
from PIL import Image, ImageGrab, ImageChops, ImageStat
def getPixelColorOne(x1, y1):
px=ImageGrab.grab((x1, y1, x1+1, y1+1)).load()
color=px[0,0]
c1, c2, c3 = color
return int(c1)
c1, c2, c3 순서대로 red, green, blue.
아래는 특정 영역의 색깔 비교하는 함수.
def pixelCheck(x1, y1, x2, y2):
im1 = ImageGrab.grab((x1, y1, x2, y2))
while True:
time.sleep(0.5)
im2 = ImageGrab.grab((x1, y1, x2, y2))
im = ImageChops.difference(im1, im2)
stat = ImageStat.Stat(im)
print(int(stat.sum[0]) + int(stat.sum[1])+int(stat.sum[2]))
728x90