python - pyautogui 在照片中多次搜索照片
问题描述
虽然在屏幕截图中不止一次找到了搜索过的“aaa.png”照片,但它只找到了 1 个。我希望它找到所有这些。我能为它做些什么
iml = pyautogui.screenshot(region=(158, 284, 628, 679))
while True:
if pyautogui.locateOnScreen('aaa.png', confidence=0.9, grayscale=True) != None:
for a in pyautogui.locateOnScreen('aaa.png'):
print(a)
输出:
407
302
81
85
...
解决方案
您想用它locateAllOnScreen
来查找所有实例。
for pos in pyautogui.locateAllOnScreen('someButton.png')
print(pos)
[更新重新评论]
我不能使用“截图”功能,但这个程序:
import pyautogui
res = pyautogui.locateAll('Dow8f.png', 'aHDB6.png',confidence=0.95, grayscale=True)
for a in res:
print(a)
给了我 25 次点击,例如:
Box(left=9, top=584, width=81, height=85)
Box(left=115, top=584, width=81, height=85)
Box(left=222, top=584, width=81, height=85)
Box(left=541, top=584, width=81, height=85)
[你没有说你使用的是哪个版本的pyautogui;如果没有来自 的匹配项,最新版本将不会返回“无” locateOnScreen
,所以也许您有旧版本?]
pyautogui Github 中的这个问题可能是相关的。默认confidence
级别可能太挑剔了,所以使用我上面显示的值。]
推荐阅读
- mysql - 如果左表有多个与其他表关联的字段,如何使用左连接?
- python - 为小于 10 的数字添加零到日期
- c# - c# main 中的非静态字段需要对象引用
- javascript - 如何上传文件和其他数据?无法理解多部分表单
- javascript - 设置 jQuery UI Spinner 来调整宽度,使文本适合
- panel - Acumatica 智能面板在打开时不显示数据
- python - TypeError:在 PyDev for Eclipse 中使用 input() 时,“str”对象不可调用
- java - 如何将 selenium 的焦点移动到新标签窗口?
- spring-boot - 给定范围内的随机服务器端口弹簧启动
- ionic-framework - ionic3 相机从缓存中移动图像并获取 base64 数据