이미지에 pyautogui를 사용하는 방법
Nov 28 2020
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
답변
1 AndrewStone Nov 29 2020 at 01:56
이것을 시도하십시오 :
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))
이 질문은 다른과 유사 하나 , 나는 두 곳에서 같은 대답을 기록했다.