有没有办法将OpenCV窗口设置为始终位于顶部? 我可以从窗口中删除最小化和关闭按钮吗? 谢谢。
答案 0 :(得分:6)
您可以使用: cvGetWindowHandle() 获得Widows处理程序。然后使用常规的Windows API,你可以做任何你喜欢的事情
答案 1 :(得分:0)
我找到了发表在评论中的最佳解决方案:Python OpenCV open window on top of other applications
例如,打开一个窗口后,只需在下面添加命令即可。
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))
答案 2 :(得分:0)
我发现我所要做的只是将主窗口设置为全屏,然后恢复正常。
#!/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)
答案 3 :(得分:-1)
对我来说,这在 macOS 中运行良好,我认为它在另一个操作系统中运行良好
destroyWindow( "windowName" );
namedWindow( "windowName", WINDOW_NORMAL );
moveWindow( "windowName", posx, posy );
imshow( "windowName", frame );
这个循环重复,顺序是: