2

So, i have this script which works, it prints out all the pixels that have and rgb value of (102,102,102) but i don't know how I would be able to now get that pixels location and click it.. any suggestions?

edit: by pixels location i mean the pixels x,y coordinates

import pyautogui
import time
from PIL import Image
import mss
import mss.tools
import cv2
import numpy as np
from PIL import ImageGrab
import colorsys


time.sleep(3)


def shootfunc(xc, yc):
    pyautogui.click(xc, yc)

gameregion = [71, 378, 328, 530]

foundpxl = 0

xx = 0
while xx <= 300:
    with mss.mss() as sct:
        region = {'top': 0, 'left': 0, 'width': 1920, 'height': 1080}
        imgg = sct.grab(region)
        pxls = imgg.pixels


        for pxl in pxls:
            for pxll in pxl:
                if pxll == (102, 102, 102) or pxl == "(255, 255, 255)" or pxl == [255, 255, 255]:
                    foundpxl = pxll
                    print(foundpxl)
        xx = xx + 1
        time.sleep(.1)
Tiger-222
  • 6,677
  • 3
  • 47
  • 60
  • Mmmm... you have a list of pixels (presumably several pixels if it's a list) and you want to click on it (presumably one pixel, else you would say *"them"*)... Which is it please? Is there a list or just one? – Mark Setchell Feb 24 '19 at 20:08

1 Answers1

1

You can enumerate any sequence you iterate over. This returns the index of the element and the element:

>>> for i, e in enumerate('abc'):
...     print(i, e)
0 a
1 b
2 c

So, you can make use of this to find the row and column of the pixel:

for row, pxl in enumerate(pxls):
    for col, pxll in enumerate(pxl):
        ...
Peter Wood
  • 23,859
  • 5
  • 60
  • 99