当前位置:   article > 正文

Python的pyautogui库(图片操作篇locateOnScreen)_pyautogui.locateonscreen

pyautogui.locateonscreen

第一篇为鼠标键盘操作https://blog.csdn.net/m0_61741706/article/details/126898352?spm=1001.2014.3001.5501

 

locateOnScreen中有region用来指定想要匹配的图片在屏幕哪个范围,grayscale可以实现灰度匹配和confidence的值决定精度

1.指定范围查询region设置在屏幕哪个区域匹配图片

  1. """
  2. region指定范围:
  3. 在locateOnScreen函数中加入region参数,可以控制找图范围,从而提高找图效率。
  4. region(x,y,width,height),其中x,y为范围左上角坐标,width,height为范围的宽和高
  5. """
  6. help_pos = pyautogui.locateOnScreen("img/ai.png",region=(x,y,width,height))#找到png图片 region中的参数为xy起始点,宽度和高度
  7. goto_pos = pyautogui.center(help_pos)#找到传回图片的中心点,并传回坐标
  8. pyautogui.moveTo(goto_pos,duration=1)#移动鼠标
  9. pyautogui.click()#点击传回的坐标

2.grayscale可以实现灰度匹配

在pyautogui.locateOnScreen()函数中加入grayscale=True,就可以实现灰度匹配
  1. """
  2. grayscale灰度匹配
  3. 在pyautogui.locateOnScreen()函数中加入grayscale=True,就可以实现灰度匹配
  4. """
  5. help_pos = pyautogui.locateOnScreen("img/ai.png", grayscale=True)#找到png图片 region中的参数为xy起始点,宽度和高度
  6. goto_pos = pyautogui.center(help_pos)#找到传回图片的中心点,并传回坐标

3.模糊查询confidence的值决定精度,数值是0到1,数值越小,精度越低

  1. """
  2. 模糊查询
  3. 在pyautogui.locateOnScreen()函数中加入confidence参数,当confidence的值决定精度
  4. """
  5. help_pos = pyautogui.locateOnScreen("img/ai.png",confidence=0.7, grayscale=True)
  6. goto_pos = pyautogui.center(help_pos)#找到传回图片的中心点,并传回坐标

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/203198
推荐阅读
相关标签
  

闽ICP备14008679号