OpenCV窗口始终位于顶部

OpenCV窗口始终位于顶部,opencv,window,Opencv,Window,有没有办法将OpenCV窗口设置为始终位于顶部? 我可以从窗口中删除最小化和关闭按钮吗? 谢谢。您可以使用: cvGetWindowHandle() 获取寡妇处理程序。然后,使用常规windows API,您可以执行任何您喜欢的操作您可以使用: cvGetWindowHandle() 获取寡妇处理程序。然后使用常规的windows API,您可以做任何您喜欢的事情我在这里的评论中找到了最好的解决方案: 只需在打开窗口后添加下面的命令,例如 cv2.namedWindow('img_file_na

有没有办法将OpenCV窗口设置为始终位于顶部? 我可以从窗口中删除最小化和关闭按钮吗? 谢谢。

您可以使用: cvGetWindowHandle() 获取寡妇处理程序。然后,使用常规windows API,您可以执行任何您喜欢的操作

您可以使用: cvGetWindowHandle()
获取寡妇处理程序。然后使用常规的windows API,您可以做任何您喜欢的事情

我在这里的评论中找到了最好的解决方案:

只需在打开窗口后添加下面的命令,例如

cv2.namedWindow('img_file_name', cv2.WINDOW_NORMAL) # Creates a window
os.system('''/usr/bin/osascript -e 'tell app "Finder" to set frontmost of process "python" to true' ''') # To make window active
使用小写的“python”。正如我在一些答案中发现的那样,使用“Python”给了我一个错误:

21:62: execution error: Finder got an error: Can’t set process "Python" to true. (-10006))

我在这里的评论中找到了最好的解决方案:

只需在打开窗口后添加下面的命令,例如

cv2.namedWindow('img_file_name', cv2.WINDOW_NORMAL) # Creates a window
os.system('''/usr/bin/osascript -e 'tell app "Finder" to set frontmost of process "python" to true' ''') # To make window active
使用小写的“python”。正如我在一些答案中发现的那样,使用“Python”给了我一个错误:

21:62: execution error: Finder got an error: Can’t set process "Python" to true. (-10006))

我发现我所需要做的就是将主窗口设置为全屏,然后恢复正常

    #!/usr/bin/env python
    import cv2
    import numpy

    WindowName="Main View"
    view_window = cv2.namedWindow(WindowName,cv2.WINDOW_NORMAL)

    # These two lines will force your "Main View" window to be on top with focus.
    cv2.setWindowProperty(WindowName,cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN)
    cv2.setWindowProperty(WindowName,cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_NORMAL)

    # The rest of this does not matter. This would be the rest of your program.
    # This just shows an image so that you can see that this example works.
    img = numpy.zeros((400,400,3), numpy.uint8)
    for x in range(0,401,100):
        for y in range(0,401,100):
            cv2.line(img,(x,0),(0,y),(128,128,254),1)
            cv2.line(img,(x,399),(0,y),(254,128,128),1)
            cv2.line(img,(399,y),(x,399),(128,254,128),1)
            cv2.line(img,(399,y),(x,0),(254,254,254),1)
    cv2.imshow(WindowName, img)
    cv2.waitKey(0)
    cv2.destroyWindow(WindowName)

我发现我所需要做的就是将主窗口设置为全屏,然后恢复正常

    #!/usr/bin/env python
    import cv2
    import numpy

    WindowName="Main View"
    view_window = cv2.namedWindow(WindowName,cv2.WINDOW_NORMAL)

    # These two lines will force your "Main View" window to be on top with focus.
    cv2.setWindowProperty(WindowName,cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN)
    cv2.setWindowProperty(WindowName,cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_NORMAL)

    # The rest of this does not matter. This would be the rest of your program.
    # This just shows an image so that you can see that this example works.
    img = numpy.zeros((400,400,3), numpy.uint8)
    for x in range(0,401,100):
        for y in range(0,401,100):
            cv2.line(img,(x,0),(0,y),(128,128,254),1)
            cv2.line(img,(x,399),(0,y),(254,128,128),1)
            cv2.line(img,(399,y),(x,399),(128,254,128),1)
            cv2.line(img,(399,y),(x,0),(254,254,254),1)
    cv2.imshow(WindowName, img)
    cv2.waitKey(0)
    cv2.destroyWindow(WindowName)

对我来说,这在macOS中可以很好地工作,我认为它在另一个操作系统中也可以很好地工作

destroyWindow( "windowName" );
namedWindow( "windowName", WINDOW_NORMAL );
moveWindow( "windowName", posx, posy );
imshow( "windowName", frame );
在循环中重复此操作,顺序为:

  • 破坏窗口,这迫使创建新窗口
  • 声明新窗口
  • 将窗口移动到您想要的位置,例如最后一个位置 位置
  • 橱窗

  • 对我来说,这在macOS中可以很好地工作,我认为它在另一个操作系统中也可以很好地工作

    destroyWindow( "windowName" );
    namedWindow( "windowName", WINDOW_NORMAL );
    moveWindow( "windowName", posx, posy );
    imshow( "windowName", frame );
    
    在循环中重复此操作,顺序为:

  • 破坏窗口,这迫使创建新窗口
  • 声明新窗口
  • 将窗口移动到您想要的位置,例如最后一个位置 位置
  • 橱窗

  • 这只适用于Mac电脑这只适用于Mac电脑你需要在全屏和普通行之间放置一个
    cv2.waitKey(1)
    ,至少在windows 10上这样也不会使窗口保持在顶部,只需将其聚焦一次即可。所以不能按要求工作。你需要在全屏和正常行之间放置一个
    cv2.waitKey(1)
    ,至少在windows 10上这样也不会使窗口保持在顶部,只需聚焦一次即可。所以不按要求工作。否决是因为它看起来更像一个提示而不是一个答案。否决是因为它看起来更像一个提示而不是一个答案。这并不能确保窗口将保持“始终在顶部”。实际上,这是对GUI的滥用。它甚至可能会阻止焦点正常工作。这并不能确保窗口“始终处于顶部”。实际上,这是对GUI的滥用。从OpenCV 3.4.8/4.1.2开始,有一种方法可以做到这一点,在这个问题的任何答案中都没有提到。从OpenCV 3.4.8/4.1.2开始,有一种方法可以做到这一点,在这个问题的任何答案中都没有提到。看见