Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fast get pixel and oparate.
#1
Hi!
I make some program to recognize pixel i few position. I try pyguiauto & PIL.
Programing with pyautogui was problematic when after 3/4min slowdown process and hole System Huh (after this PyCharm report me to stop process of program). I guess pyautogui don't have clearing cash or temp(hmm everytime after matching colors?).
I use this
pyautogui.pixelMatchesColor(x, y, (R, G, B), tolerance=10)
In code every 500/200ms it take 13 diffrend positions.

Afterall i try use PIL and ImageGrab. But from start i feel little laggy like screen freez. I dont have this time unstablle working. After even 1h still work.no leaking memory. Confused

My question is:
-Where I make mistake, I doing something wrong with pyautogui?
-I only try my code without compile in PyCharm, it will incrase efficity when i compile to exe?
-do you have guys any idea how to make? got something else better then this?
-maybe betther option is to capture hole screen at onece and take 13 pixels ? (i dont know how to do that)


my last working part of code:
    def takeitt(self):
        global r, g, b
        pixelColor = ImageGrab.grab(bbox=(x, y, x + 2, y + 2)).getpixel((1, 1))
        r = pixelColor[0]
        g = pixelColor[1]
        b = pixelColor[2]
    def hp80_check(self):
        global x, y, hp80
        i = 3
        x = arr[i, 2]
        y = arr[i, 3]
        self.takeitt()
        if r == arr[i, 4] and g == arr[i, 5] and b == arr[i, 6]:
            hp80 = 1
        else:
            hp80 = 0
hp80 is a 1 matchpixel from 13 differnd def.
they mixing in one time in one loop/tick in hole code
Reply
#2
Perhaps this question should be directed to the author: https://pypi.org/user/AlSweigart/
Reply
#3
yes ty, but i think is not best way going to developer with some small problem (i think).
someone know any command for clearing cash or mem /temp for pyautogui?
Reply
#4
here is example difference between PIL and autogui:
interaction for PIL is 6/7 peer seconds
interaction for autogui is 150/peer seconds
Issue:
PIL little laggy pc
autogui after 10.000 interaction got error and program stop

def check(self):
        global licznik
        x=arr[1, 2]
        y=arr[1, 3]

        #print('x:',arr[1,2],'y:',arr[1, 3],'   RGB:',arr[1, 4], arr[1, 5], arr[1, 6])
        licznik += 1

        pixelColor = ImageGrab.grab(bbox=(x, y, x + 2, y + 2)).getpixel((1, 1))
        if pixelColor[0] == arr[1, 4] and pixelColor[1] == arr[1, 5] and pixelColor[2] == arr[1, 6]:
            bar = 1
        else:
            bar=0

        #print(pixelColor)
        #bar = pyautogui.pixelMatchesColor(x - 1, y + 1, (arr[1, 4], arr[1, 5], arr[1, 6]), tolerance=10)
        if bar:
            print('jest')
            t2 = time.time()
            tf = t2 - t1
            it_per_sec = int(licznik / tf)
            self.display3.config(text=str(it_per_sec) + "  iteraction/sec")
        if bar == 0:
            print('nope')
Reply
#5
ok guys i think i solve problem update pyautogui:D
Reply
#6
Please share so others with same issue will have answer,
Thanks
Reply
#7
Pyautogui autor have msg from other PPL who report him same problem. After 10.000 asq pyautogui about pixel match, get pixel etc.. Script stopped. He repair his own code and now work smooth. So Just update to New version pyautogui and use pyautoguitmatchpixel. Some Times stuck program if too much frq ask about pixel peer second. But is no problem program still tuning and no stop. Only libray Windows are So slow;). So be below 30 iteractions peer second. If you need more: make in root loop and after 200 loops stop Geting pixel and run again. It's helpfull.
Reply
#8
Thanks for sharing
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Voxel to pixel graphics voicemail 3 567 Nov-19-2023, 09:45 AM
Last Post: paul18fr
  Pixel color and action Sartre 4 2,059 Apr-13-2023, 03:26 AM
Last Post: Sartre
  Dynamic pixel display jerryf 2 719 Mar-17-2023, 07:26 PM
Last Post: jerryf
  Plotting Pixel Intensity Doev 0 1,717 Oct-21-2020, 10:56 PM
Last Post: Doev
  What is the best way to search for a pixel in a screenshot? TheZadok42 1 2,587 May-15-2020, 12:37 PM
Last Post: scidam
  random change of color pixel with PIL louloudevinci 4 8,457 May-31-2018, 03:55 PM
Last Post: louloudevinci

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020