9

Edit to include code snippet.

I am developing an app with pyautogui. I want to match a region on the desktop and click it. Calling the locateOnscreen function, I pass the filename containing the image to match, along with a confidence parameter, which throws an error.

import pyautogui as pag
button_login = pag.locateOnScreen("button_login.png", confidence=0.7)

File ".\test.py", line 23, in <module>
button_login = pag.locateOnScreen("button_login.png", confidence=0.7)
...
TypeError: _locateAll_python() got an unexpected keyword argument 'confidence'

Installed version is 0.9.47. The docs refer to version 1.0.0. I can't find this version anywhere including pypi and github.

undercoverincel
  • 89
  • 1
  • 1
  • 4

2 Answers2

12

This happens because the function locateOnScreen can reach two different functions (source code):

  • _locateAll_opencv if cv2 / OpenCV is installed

  • _locateAll_python if cv2 / OpenCV cannot be found or if you are using python3 with a version of cv2 inferior to 3

And _locateAll_python doesn't handle the confidence parameter.

So you can try to install/update OpenCV if you need this feature : https://pypi.org/project/opencv-python/

pip install opencv-python

Or if you have python 2 & 3 on your system:

pip3 install opencv-python
JayRizzo
  • 3,234
  • 3
  • 33
  • 49
PRMoureu
  • 12,817
  • 6
  • 38
  • 48
1

pip install opencv-python

pyautogui uses OpenCV in the back end to calculate confidence, and therefore it needs to be installed in Python before you can use the Confidence argument. Good luck.

Sean
  • 680
  • 7
  • 10
  • Hi! This seems to be what the other answer that's already been there for a while recommends. Could you maybe edit your answer to clarify how your answer is different? – Alex Waygood Sep 18 '21 at 22:13