我目前正在使用PyAutoGUI作为locate函数,该函数在haystackImage
上搜索needleImage
。文档提供的示例包含图像的路径。但是,我有一个函数,它将一系列needleImage
与单个haystackImages
进行比较,并且在需要检查的次数内读取同一图像文件的效率非常低
有没有办法避免每次都读heystackImage
?如果没有,除了使用BuffereImage的pyautogui/pyscreeze定位函数外,还有其他方法吗
...
checks = {
"recieve.png": 'recieve',
"next.png": 'next',
"start.png": 'start',
"black.png": 'loading',
"loading.png": 'loading',
"gear.png": 'home',
"factory.png": 'factory',
"bathtub.png": 'bathtub',
"refit.png": 'refit',
"supply.png": 'supply',
"dock.png": 'dock',
# SPE
"spepage.png": 'spe',
"expeditionpage.png": 'expedition',
"sortiepage.png": 'sortie',
"practice.png": 'practice',
"practiceinfo.png": 'practice',
"oquest.png": 'quest',
"quest.png": 'quest'
}
for key in checks:
if (detect(key, cache=True)):
return checks[key]
def detect(imgDir, confidence=0.85, cache=False):
if (pyautogui.locate(os.path.join('images', imgDir), 'images\\capture.jpeg', confidence=confidence)) is not None:
return True
else:
return False
pyautogui.locate()
还接受numpy数组和PIL图像作为输入。您可以将haystack图像读取到numpy数组(BGR)或PIL图像中,并传递该图像而不是文件名第二种方法可能比第一种方法慢,因为
pyautogui.locate()
最终将PIL图像作为numpy数组加载,这需要额外的处理相关问题 更多 >
编程相关推荐