【问题标题】:OpenCV window must appear in front of all windowsOpenCV 窗口必须出现在所有窗口的前面
【发布时间】:2018-05-24 10:07:43
【问题描述】:

我有一个 GUI 对话框,其中包含一些按钮,单击这些按钮将调用一个函数来显示图像。但是,当单击该按钮时,OpenCV 的窗口会显示在对话框后面。单击按钮时,我希望 OpenCV 窗口出现在其前面。

这是创建窗口并显示图像的代码的sn-p。

    cv2.namedWindow('image',0)
    cv2.resizeWindow('image',1200,720)

    while(1):
        cv2.imshow('image', self.img_res)
        k = cv2.waitKey(1) & 0xFF
        if k == ord('m'):
            res = 1
            break
        elif k == 27:
            break

我已经看到了一些关于 win32gui 模块的示例,但我不知道如何在这里使用它。

(我在 Windows 中使用 Python 2.7)

【问题讨论】:

    标签: python python-2.7 opencv window


    【解决方案1】:

    我不知道你的完整代码,但是当我这样尝试时,它停留在窗口前面。希望对您有所帮助!

    import tkinter as tk
    from tkinter import *
    import cv2
    
    class GUI:
        def __init__(self, master):
            self.event = 1
            self.master = master
            self.img_res = img = cv2.imread('image.jpg', 0)
            self.b = Button(self.master, text='Show image', command=self.window)
            self.b.pack()
    
        def window(self, event=None):
            while self.event == 1:
                cv2.imshow('image', self.img_res)
                k = cv2.waitKey(1) & 0xFF
                if k == ord('m'):
                    res = 1
                    break
                elif k == 27:
                    break
    
    
    def main(): 
        root = tk.Tk()
        app = GUI(root)
        root.mainloop()
    
    if __name__ == '__main__':
        main()
    

    加法:

    你也可以试试 import ctypes

    import ctypes
    
    ctypes.windll.kernel32.GetConsoleWindow()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-08-12
      • 1970-01-01
      • 2010-12-27
      • 2014-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多