Home > Net >  Pyautogui compare two nearly identical images and return desired one
Pyautogui compare two nearly identical images and return desired one

Time:08-06

How would you go about using image detection on two very similar images im trying to use the code below to find when the volume icon changes from full to low but the icon overall is very similar and code below is returning the icon regardless of whether its full or low, i've tried using confidence but doesn't seem to change anything i am wanting to detect when the low sound icon is active.

On the application these icons are in the same spot and change when you walk in objects eg bushes, etc

Images im talking about are below

https://imgur.com/a/k7wXWcK

Low volume sound icon

High volume sound icon

I've attempted changing my confidence as it finds wrong one at 0.78 but at 0.77 it just cant find anything.

sound_image = None
while (sound_image == None):
    try:
        print("Found img")
        sound_image = pyautogui.locateOnScreen(os.getcwd()   "\images\misc\low_sound.png", confidence=0.77)
    except:
        print("Failed to find img try again 10 seconds")
        time.sleep(10)

CodePudding user response:

Seems to me the high volume icon is just the low volume one with an extra arc. So it's no surprise pyautogui finds the low volume icon when there is a high volume one, as the low volume icon is literally a part of the high volume one.

Thus, you will need some extra logic to differentiate between the two icons. You could do it like this (pseudocode):

find_high_volume_icon()
if (found_high_volume_icon):
    Great, it's the high volume one!
else:
    find_low_volume_icon()
    if (found_low_colume_icon):
        It has to be the low volume one, because we didn't find the high one earlier
    else:
        None of the icons were found, they are probably not on screen
  • Related