I'm trying to automate a task in a full screen game as a QOL improvement. This means reading a value from a screenshot of the game, and if my set conditions are met, locate the image and right click on it.
I'm having trouble using the pyautogui locateCenterOnScreen function, it always returns None.
This is the part I'm having trouble with :
import pyautogui
import time
pyautogui.size()
(1920, 1080)
pyautogui.FAILSAFE = True
time.sleep(3)
imageLocation = pyautogui.locateCenterOnScreen('myfilepath')
print (imageLocation)
The delay is there to make sure I have enough time to open the game. I've used pyautogui to take screenshots in-game in order to use OCR to read from it, which seems to be working just fine. But for some reason I can't make the image recognition work.
I've tried to just use a small portion of the image that always remains static, and even used pyautogui to screenshot the region to see if using it's own generated image of the object would work. I've tried having the game in windowed mode, but nothing seems to work. Not sure if it matters, but I've tried both JPG and PNG file format for the images.
Can anyone see where I'm going wrong?
It works when I have PyCharm open and search for this :
So the function seems to be working as it should, but it can't find it in game. Also, I've tried using the grey scale option but it still didn't work.
I'd really appreciate some help.
Thanks in advance
Ziggy
On the off chance that someone finds this and has the same problem, I solved this by using OpenCV instead of pyautogui to locate the images. It works perfectly, as you can see in the screenshot provided. Enjoy!
OpenCV locating images in fullscreen game
https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_tutorials.html