[英]Python OpenCV open window on top of other applications
When executing an OpenCV python script containing: cv2.imshow(img)
the resulting window opens behind my terminal window. 当执行包含以下
cv2.imshow(img)
的OpenCV python脚本: cv2.imshow(img)
,生成的窗口将在我的终端窗口后面打开。 This is a mild irritation - is there any way to get it to initially open in front / on top? 这是一种轻微的刺激 - 有没有办法让它最初在前面/上面打开?
A number of people have asked questions ( here and here ) about forcing persistent behaviour but this is, I think, simpler. 许多人提出了关于强迫持久行为的问题( 这里和这里 ),但我认为这更简单。
Platform OS X and OpenCV 2.4.11 平台OS X和OpenCV 2.4.11
One way to work around this would be to set all windows from OpenCV "frontmost" using AppleScript. 解决这个问题的一种方法是使用AppleScript将OpenCV中的所有窗口设置为“最前面”。
subprocess.call(["/usr/bin/osascript", "-e", 'tell app "Finder" to set frontmost of process "Python" to true'])
This way, all windows should be brought to the front. 这样,所有窗户都应该放在前面。
Open a namedWindow
before imshow
, for instance: 打开
namedWindow
之前imshow
,例如:
cv2.namedWindow('ImageWindowName', cv2.WINDOW_NORMAL)
cv2.imshow('ImageWindowName',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
Comment if this makes any different. 评论是否有任何不同。
I can do what I think you want by adding a single line to the following file in the OpenCV distribution: 我可以通过在OpenCV发行版中的以下文件中添加一行来完成我认为您想要的操作:
modules/highgui/src/window_cocoa.mm
It is around line 568, and is the single line after the word SETCHELL
in the code below: 它位于第568行
SETCHELL
,是下面代码中单词SETCHELL
之后的SETCHELL
:
[window setFrameTopLeftPoint:initContentRect.origin];
[window setFirstContent:YES];
[window setContentView:[[CVView alloc] init]];
[window setHasShadow:YES];
[window setAcceptsMouseMovedEvents:YES];
[window useOptimizedDrawing:YES];
[window setTitle:windowName];
[window makeKeyAndOrderFront:nil];
// SETCHELL - raise window to top of stacking order
[window setLevel:CGWindowLevelForKey(kCGMaximumWindowLevelKey)];
[window setAutosize:(flags == CV_WINDOW_AUTOSIZE)];
[windows setValue:window forKey:windowName];
[localpool drain];
return [windows count]-1;
}
CV_IMPL int cvWaitKey (int maxWait)
{
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.