赞
踩
第一篇为鼠标键盘操作https://blog.csdn.net/m0_61741706/article/details/126898352?spm=1001.2014.3001.5501
locateOnScreen中有region用来指定想要匹配的图片在屏幕哪个范围,grayscale可以实现灰度匹配和confidence的值决定精度
1.指定范围查询region设置在屏幕哪个区域匹配图片
- """
- region指定范围:
- 在locateOnScreen函数中加入region参数,可以控制找图范围,从而提高找图效率。
- region(x,y,width,height),其中x,y为范围左上角坐标,width,height为范围的宽和高
- """
- help_pos = pyautogui.locateOnScreen("img/ai.png",region=(x,y,width,height))#找到png图片 region中的参数为xy起始点,宽度和高度
- goto_pos = pyautogui.center(help_pos)#找到传回图片的中心点,并传回坐标
- pyautogui.moveTo(goto_pos,duration=1)#移动鼠标
- pyautogui.click()#点击传回的坐标
2.grayscale可以实现灰度匹配
在pyautogui.locateOnScreen()函数中加入grayscale=True,就可以实现灰度匹配
- """
- grayscale灰度匹配
- 在pyautogui.locateOnScreen()函数中加入grayscale=True,就可以实现灰度匹配
- """
- help_pos = pyautogui.locateOnScreen("img/ai.png", grayscale=True)#找到png图片 region中的参数为xy起始点,宽度和高度
- goto_pos = pyautogui.center(help_pos)#找到传回图片的中心点,并传回坐标
3.模糊查询confidence的值决定精度,数值是0到1,数值越小,精度越低
- """
- 模糊查询
- 在pyautogui.locateOnScreen()函数中加入confidence参数,当confidence的值决定精度
- """
- help_pos = pyautogui.locateOnScreen("img/ai.png",confidence=0.7, grayscale=True)
- goto_pos = pyautogui.center(help_pos)#找到传回图片的中心点,并传回坐标
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。