Como usar o pyautogui para imagens
Nov 28 2020
Eu queria saber se seria possível fazer pyautogui.locateOnScreen()
para uma pasta completa isso é o que quero dizer uma pasta com 20 imagens diferentes e encontrá-los na tela. É possível fazer com pyautogui
? ou então como você faria isso?
Este é o meu código até agora:
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)
eu recebo este erro se eu executar este código TypeError: expected an image filename, OpenCV numpy array, or PIL image
Respostas
1 AndrewStone Nov 29 2020 at 01:56
Experimente isto:
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))
Esta questão é semelhante a outro um , eu postei a mesma resposta em ambos os lugares.
O que significa um erro “Não é possível encontrar o símbolo” ou “Não é possível resolver o símbolo”?
George Harrison ficou chateado por suas letras de 'Hurdy Gurdy Man' de Donovan não terem sido usadas