PYTHON - How to know if there is an object on the screen from a reference?

Asked

Viewed 2,169 times

1

Basically I wanted to know if there is the possibility of knowing if there is an object on the screen from a reference

Example: There is a generic program on the screen that displays a closed lock, and when you make an action the lock is displayed open, the python program recognizes the open lock image and makes an action when it happens.

basically like scanning the screen looking for this open padlock, having an image as a reference, in case I load a small image with this open padlock, and when the program sees that on the screen has the same thing as in the reference image it makes an action!

resolution that I thought, print the screen every second, and compare if in the print there is any piece equal to the reference image that I previously loaded and if yes returns it. (but it sounds to me like gambiarra, and the print taken would always have to overwrite the previous to not have multiple prints )

I’ve seen some things of OpenCv where it is possible to take an image with text and transfer the text of the image to a String, however it could be done the process of checking in an image if there is another image?

what I need to study?

1 answer

3


I did something similar for days with the library pyautogui, following example:

import pyautogui

icon_pos = pyautogui.locateOnScreen('cadeado_aberto.png')

if icon_pos:
    print(icon_pos)
    print("Existe um cadeado aberto na tela")
else:
    print("Não existe nenhum cadeado aberto na tela")

Documentation pyautogui

  • 1

    I had arrived at this result too, but I was using the syntax a little different: if(icon_pos != None): action but thanks for the contribution, already helps other people with the same doubt! : 3

Browser other questions tagged

You are not signed in. Login or sign up in order to post.