用过pyautogui的同学应该都知道,locateOnScreen可以传入一张图片与当前屏幕(截屏)进行匹配,但是我的需求是能基于已经截屏的图片来进行图像定位,看了pyautogui的源码没有相关的接口,突发奇想自己定义一个。
首先,参考locateOnScreen的源码
/usr/local/lib/python3.9/site-packages/pyautogui/__init__.py
@raisePyAutoGUIImageNotFoundException
def locateOnScreen(*args, **kwargs):
return pyscreeze.locateOnScreen(*args, **kwargs)
/usr/local/lib/python3.9/site-packages/pyscreeze/__init__.py
def locateOnScreen(image, minSearchTime=0, **kwargs):
"""TODO - rewrite this
minSearchTime - amount of time in seconds to repeat taking
screenshots and trying to locate a match. The default of 0 performs
a single search.
"""
start = time.time()
while True:
try:
screenshotIm = screenshot(region=None) # the locateAll() function must handle cropping to return accurate coordinates, so don't pass a region he

最低0.47元/天 解锁文章
1314

被折叠的 条评论
为什么被折叠?



