asweigart / pyautogui

A cross-platform GUI automation Python module for human beings. Used to programmatically control the mouse & keyboard.
BSD 3-Clause "New" or "Revised" License
10.15k stars 1.23k forks source link

confidence parameter not working with opencv-python v 4.7.0.72 #771

Open Maxim-Ryzhenkov opened 1 year ago

Maxim-Ryzhenkov commented 1 year ago

The 'confidence' parameter in the 'locate_on_screen' method doesn't work with opencv-python v 4.7.0.72 The stacktrace output looks like the library is not installed, but it is not. The error appeared when upgrading from version 4.5.4.60. Rolling back opencv to an older version solved the problem.

obj = pyautogui.locateOnScreen(self.locator, region=region, confidence=confidence, minSearchTime=search_time) File "C:\Python\Python38\lib\site-packages\pyautogui__init.py", line 175, in wrapper return wrappedFunction(*args, **kwargs) File "C:\Python\Python38\lib\site-packages\pyautogui\init.py", line 213, in locateOnScreen return pyscreeze.locateOnScreen(*args, **kwargs) File "C:\Python\Python38\lib\site-packages\pyscreeze\init.py", line 373, in locateOnScreen retVal = locate(image, screenshotIm, **kwargs) File "C:\Python\Python38\lib\site-packages\pyscreeze\init.py", line 353, in locate points = tuple(locateAll(needleImage, haystackImage, **kwargs)) File "C:\Python\Python38\lib\site-packages\pyscreeze\init__.py", line 253, in _locateAll_python raise NotImplementedError('The confidence keyword argument is only available if OpenCV is installed.') NotImplementedError: The confidence keyword argument is only available if OpenCV is installed.

jtranquilli commented 11 months ago

Could you provide the code you were using that resulted in this issue? I was able to replicate that error but it was fixed by installing python-opencv.

Pandafishie commented 1 month ago

Could you provide the code you were using that resulted in this issue? I was able to replicate that error but it was fixed by installing python-opencv.

- @jtranquilli

That can not be true because there is no "python-opencv" package. You likely meant "opencv-python". Your comment was absolutely no help and not regarding the topic.

I'm having the same issue.

python code: py import pyautogui ImageBox = pyautogui.locateOnScreen(image, grayscale=grayscale, confidence=confidence)

pip-freeze & py -v: opencv-python==4.10.0.84 PyAutoGUI==0.9.54 Python 3.11.9 @ conda 24.7.1 @ Win11

Error: File "%User%\anaconda3\Lib\site-packages\pyscreeze\__init__.py", line 273, in _locateAll_pillow raise NotImplementedError('The confidence keyword argument is only available if OpenCV is installed.') NotImplementedError: The confidence keyword argument is only available if OpenCV is installed.

@Maxim-Ryzhenkov what opencv - version did you roll back to? 4.5.X?

Maxim-Ryzhenkov commented 1 month ago

I have a working version opencv-python 4.6.0.66 installed