【发布时间】:2020-08-07 12:46:38
【问题描述】:
我是编码初学者。我使用 python 和 windows 10
我编写了一个非常简单的代码,它捕获然后打开一个图像,然后循环匹配模板,以便使用包含所有可能答案的列表来确定该图像中的对象是什么。代码使用pyautogui和opencv:
import pyautogui
import cv2 as cv
def my_func():
#train image
pyautogui.screenshot("train.png") #I am looking at the picture of an animal and the robot takes a screenshot and stores it.
train_img = cv.imread("train.png", 0)
#Contains all the images to iterate through
template_list = ["apple.png", "person.png", "animal.png"]
for i in template_list:
#template image
template_img = cv.imread(i,0)
#match template
result = cv.matchTemplate(train_img, template_img, cv.TM_CCOEFF_NORMED)
min_val, max_val, min_loc, max_loc = cv.minMaxLoc(result)
if max_val >= .85:
print(i) #prints the name of the matched image
return True
print("could not match the train image to one of the available templates.")
return False
预期的输出仅供控制台打印:
animal.png
我想创建一个应用程序、一个窗口或任何类似的东西,您可以在其中单击一个“运行”按钮,然后代码就会运行。完成后,它将显示控制台日志。
你可以用 VS Code 做到这一点,但是当代码运行时,我看不到控制台日志(因为我需要转到将截图的图像)并且我希望能够看到它。
所以我的问题是:
是否可以为 Windows 创建一个桌面应用程序来执行此任务?
该应用程序可以在我以外的其他计算机上运行吗?
您是否推荐任何其他替代方案?
【问题讨论】:
-
是的,可以创建这样的应用程序。搜索 Tkinter,它是一个 GUI 工具包,我认为它会给你带来奇迹。如果您让用户能够在他们的计算机上选择图像,它也可以在其他计算机上运行。
-
谢谢!在我发布了这个问题之后,我实际上发现了一组非常不错的 100 多个由 John Alder 编写的关于 Tkinter 的视频教程。
-
太好了,祝你好运
标签: python windows opencv pyautogui