【问题标题】:Is it possible to create a desktop application with python and imported libraries?是否可以使用 python 和导入的库创建桌面应用程序?
【发布时间】: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


【解决方案1】:

感谢@The Laggy Tablet,我做了一些研究,发现了 100 多个由 John Alder 撰写的关于 Tkinter 的 youtube 视频教程。我不确定我是否可以发布链接,所以我不会,但是很容易找到。

它实际上很容易使用,当你完成它并将其制作成一个实际的 GUI 时,其他人可以使用它而无需安装任何依赖项,甚至不需要安装 Python。

希望这对将来的某人有所帮助。干杯!

【讨论】:

  • 很高兴帮助队友
猜你喜欢
  • 2011-05-01
  • 1970-01-01
  • 2020-09-22
  • 2012-02-06
  • 1970-01-01
  • 1970-01-01
  • 2017-11-26
  • 1970-01-01
相关资源
最近更新 更多