我想知道是否可以这样做pyautogui.locateOnScreen()
对于完整的文件夹,我的意思是一个包含 20 个不同图像的文件夹,并在屏幕上找到它们。是否可以做pyautogui
?否则你会怎么做?
到目前为止,这是我的代码:
from pyautogui import locateAllOnScreen as find
import os
import numpy as np
def try_to_find(x):
x = os.path.isfile(x)
if x == None:
Warning('No images were enterd')
else:
folder = x
value = find(folder)
if value is not None:
print(f"{x} was found!")
else:
if value is None:
print(f"{x} was not found!")
return(list(value))
myfolder = ("ImageQuery")
found = 0
with os.scandir(myfolder) as entries:
for entry in entries:
if entry.is_file():
found+=1
print(f'Items {found}: {entry.name}')
try_to_find(entry.name)
如果我运行此代码,我会收到此错误TypeError: expected an image filename, OpenCV numpy array, or PIL image
试试这个:
import os
import pyautogui as py
image_list = []
# Get list of all files in current directory
directory = os.listdir()
# Find files that end with .png or .jpg and add to image_list
for file in directory:
if file.endswith('.png') or file.endswith('.jpg'):
image_list.append(file)
# Loop through list to find all the images
for image in image_list:
print(image)
print(py.locateOnScreen(image))
这个问题和另一个问题类似one https://stackoverflow.com/questions/65044841/pyautogui-locateonscreen-for-multiple-images,我在两个地方都发布了相同的答案。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)