When executing an OpenCV python script containing: cv2.imshow(img)
the resulting window opens behind my terminal window. 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
OpenCV is written in C and C++ whereas PIL is written using Python and C, hence just from this information, OpenCV seems faster. While dealing with 1000s of images for data extraction, the processing speed 🚀 matters. Here is a quick comparison of these two libraries.
. read() in OpenCV returns 2 things, boolean and data. If there are not 2 variables, a tuple will be assigned to one variable. The boolean is mostly used for error catching.
Python OpenCV – moveWindow() FunctionIf we want to show image windows at a specific position moveWindow() function of OpenCV will do it. Syntax: cv2.moveWindow(window_Name,x,y) Parameters: window_name: name of the window which you want to move at particular position. x: Value of x coordinate.
OpenCV is a Python open-source library, which is used for computer vision in Artificial intelligence, Machine Learning, face recognition, etc.
One way to work around this would be to set all windows from OpenCV "frontmost" using AppleScript.
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.
I can do what I think you want by adding a single line to the following file in the OpenCV distribution:
modules/highgui/src/window_cocoa.mm
It is around line 568, and is the single line after the word SETCHELL
in the code below:
[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)
{
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With