Python OpenCV open window on top of other applications

前端 未结 3 1110
南旧
南旧 2020-12-17 09:57

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 an

相关标签:
3条回答
  • 2020-12-17 10:20

    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.

    0 讨论(0)
  • 2020-12-17 10:33

    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)
    {
    
    0 讨论(0)
  • 2020-12-17 10:33

    Open a namedWindow before imshow, for instance:

    cv2.namedWindow('ImageWindowName', cv2.WINDOW_NORMAL)
    cv2.imshow('ImageWindowName',img)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
    

    Comment if this makes any different.

    0 讨论(0)
提交回复
热议问题