Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在桌面屏幕上成功实时检测多个图像[Python、tkinter、pyautogui]_Python_User Interface_Opencv_Tkinter_Pyautogui - Fatal编程技术网

如何在桌面屏幕上成功实时检测多个图像[Python、tkinter、pyautogui]

如何在桌面屏幕上成功实时检测多个图像[Python、tkinter、pyautogui],python,user-interface,opencv,tkinter,pyautogui,Python,User Interface,Opencv,Tkinter,Pyautogui,编程新手,stackoverflow社区的新成员。为了实现这段代码的目的,我一直在阅读这里的主题、有关所用流程的教程等 我的项目是关于一个4人在线纸牌游戏(tichu),在那里我需要计算实时玩的牌数(总共56张牌)。因此我制作了一个显示可用牌数的窗口(tkinter)。我使用每张卡的一小部分(12x24像素)来匹配桌面(玩游戏的地方)。程序会扫描屏幕上显示的每一张卡,如果找到,就会在GUI上用较暗的图标替换。当游戏中显示重置按钮时,GUI将重置(pyautogui)。这里的问题是,GUI的扫描和

编程新手,stackoverflow社区的新成员。为了实现这段代码的目的,我一直在阅读这里的主题、有关所用流程的教程等

我的项目是关于一个4人在线纸牌游戏(tichu),在那里我需要计算实时玩的牌数(总共56张牌)。因此我制作了一个显示可用牌数的窗口(tkinter)。我使用每张卡的一小部分(12x24像素)来匹配桌面(玩游戏的地方)。程序会扫描屏幕上显示的每一张卡,如果找到,就会在GUI上用较暗的图标替换。当游戏中显示重置按钮时,GUI将重置(pyautogui)。这里的问题是,GUI的扫描和刷新速度非常慢,并且错过了许多卡片(导致下一个玩家移动)。我希望该程序能够实时扫描所有56张卡的可用性。可能吗?opencv是解决方案吗?我没有在我的代码中实现它的线索:/

程序开始运行,等待显示卡片。它只能识别大小和分辨率完全相同的卡。读取“reset.png”图像时,程序停止

下面是要测试的代码和屏幕截图:

    from Tkinter import *
    from PIL import Image, ImageTk
    import pyautogui

    root = Tk()
    root.title("Available Cards Playing")

    for i in range(4):
        for j in range(14):
            tableCard = 'c%d%d' % (i, j) # building GUI table
            photo = PhotoImage(file='card_table/'+tableCard+'.gif')
            l = Label(image=photo)
            l.image=photo
            l.grid(row=i, column=j, sticky=NSEW)
    root.attributes("-topmost", True) # window always on top
    root.attributes("-toolwindow", 1) # window no minimize
    loop = 0
    while loop < 1: # program is running infinitelly till we close the window
        resetTable = pyautogui.locateCenterOnScreen('cards/reset.png')
        if resetTable is None:
            for i in range(4):
                for j in range(14):
                        sCard = 's%d%d' % (i, j) # 56 cards one-by-one are being scanned
                        checkCard = pyautogui.locateCenterOnScreen('cards/'+sCard+'.png')
                        if type(checkCard) == tuple: # checking if card was founded, then disable it on GUI
                                shadow = PhotoImage(file='card_table/dc%d%d.gif' % (i, j))
                                l = Label(image=shadow)
                                l.image=shadow
                                l.grid(row=i, column=j, sticky=NSEW)
                                root.update()

        elif type(resetTable) == tuple: # if reset button is scanned, GUI resets 
            for i in range(4):
                for j in range(14):
                    #
                    tableCard = 'c%d%d' % (i, j)
                    photo = PhotoImage(file='card_table/' + tableCard + '.gif')
                    l = Label(image=photo)
                    l.image = photo
                    l.grid(row=i, column=j, sticky=NSEW)
                    root.update()
    root.mainloop()
从Tkinter导入*
从PIL导入图像,ImageTk
导入pyautogui
root=Tk()
root.title(“可用的纸牌游戏”)
对于范围(4)中的i:
对于范围(14)内的j:
tableCard='c%d%d'(i,j)#构建GUI表
photo=PhotoImage(file='card_table/'+tableCard+'.gif')
l=标签(图像=照片)
l、 图像=照片
l、 网格(行=i,列=j,粘性=NSEW)
root.attributes(“-topmost”,True)#窗口始终位于顶部
root.attributes(“-toolwindow”,1)#窗口号
循环=0
当循环<1时:#程序无限运行,直到我们关闭窗口
resetTable=pyautogui.locatecenter屏幕('cards/reset.png')
如果“可重置”为“无”:
对于范围(4)中的i:
对于范围(14)内的j:
sCard='s%d%d'(i,j)#正在逐个扫描56张卡
checkCard=pyautogui.locatecenter屏幕('cards/'+sCard+'.png'))
如果type(checkCard)=tuple:#检查是否建立了卡,然后在GUI上禁用它
shadow=PhotoImage(file='card_table/dc%d%d.gif'%(i,j))
l=标签(图像=阴影)
l、 图像=阴影
l、 网格(行=i,列=j,粘性=NSEW)
root.update()
elif类型(可重置)=元组:#如果扫描了重置按钮,GUI将重置
对于范围(4)中的i:
对于范围(14)内的j:
#
tableCard='c%d%d'(i,j)
photo=PhotoImage(file='card_table/'+tableCard+'.gif')
l=标签(图像=照片)
l、 图像=照片
l、 网格(行=i,列=j,粘性=NSEW)
root.update()
root.mainloop()
你可以用它来测试功能

这里是该项目与.py和所有图像(173kb)的临时链接 这样您就可以尝试它的功能了

先发制人
吉奥

那么,如果这些卡片被渲染,这意味着prosses知道它们是谁,或者是由第三方prosses渲染的,那么这个过程每毫秒为这些卡片渲染一次桌面。但是一个接一个的扫描使得它非常慢。我想让它多扫描几张卡至少*让我们说至少每种颜色同时。但事实并非如此。我想多扫描多任务。希望我能帮助你。你可以在上传了给定屏幕截图的情况下尝试应用程序。好吧,如果卡片被渲染,这意味着prosses知道他们是谁,或者是由第三方prosses渲染的?该过程每毫秒为卡片渲染一次桌面。但是一个接一个的扫描使得它非常慢。我想让它多扫描几张卡至少*让我们说至少每种颜色同时。但事实并非如此。我想多扫描多任务。希望我能帮助你。您可以使用上传的给定屏幕截图尝试该应用程序。