छवियों के लिए pyutogui का उपयोग कैसे करें
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))
यह सवाल एक और के समान है एक , मैं दोनों स्थानों पर एक ही उत्तर पोस्ट।