1

I see it is possible to resize window with OpenCV, for example:

import cv2
img = cv2.imread('Test.jpg')
cv2.imshow('image',img)
cv2.namedWindow('image',cv2.WINDOW_NORMAL)
cv2.resizeWindow('image', 600,600)
cv2.waitKey(0)
cv2.destroyAllWindows()

But is it possible to minimize current window?


I think this is maybe cv2.setWindowProperty()this function for example here is fullscreen

cv2.namedWindow("window", cv2.WND_PROP_FULLSCREEN)
cv2.setWindowProperty("window",cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN)
cv2.imshow("window", img)
Sec Cam
  • 67
  • 4
  • 12
  • @DanMašek I think this is not duplicate because I need this for openCV. In duplicate question is not asking for openCV function. – Sec Cam Aug 02 '17 at 20:36
  • @DanMašek do you know any answer for linux or only for windows? – Sec Cam Aug 02 '17 at 20:40
  • The thing is, as far as I can tell, OpenCV doesn't expose this functionality, so if there's any way to do it, you'll have to look for some generic way for the GUI backend used. It might be just easier to write your own simple GUI using something like tkinter, which will give you much more flexibility. | This might be a useful feature to add to OpenCV -- why don't you try suggesting such feature in their [issue tracker](https://github.com/opencv/opencv/issues/) – Dan Mašek Aug 02 '17 at 21:08

2 Answers2

2

Well, there is no function/method in openCV official documentation to minimize the window automatically. You can try different method with python to do the task. Such method can be found here: Is there a way to minimize a window in Windows 7 via Python 3?

Though i'm posting it here too for complete reference:

To minimize a window you need to know either the title of the window, or its window class. The window class is useful when the exact window title is not known. For example the following script shows two different ways to minimize the Microsoft Windows Notepad application assuming:

import ctypes

notepad_handle = ctypes.windll.user32.FindWindowW(None, "Untitled - Notepad")
ctypes.windll.user32.ShowWindow(notepad_handle, 6)

notepad_handle = ctypes.windll.user32.FindWindowW(u"Notepad", None) 
ctypes.windll.user32.ShowWindow(notepad_handle, 6)

To determine the class name to use, you would need to use an tool such as Microsoft's Spy++. Obviously if Notepad was opened with a file, it would have a different title such as test.txt - Notepad. If this was the case, the first example would now fail to find the window, but the second example would still work.

If two copies of notepad were running, then only one would be closed. If all copies needed to be closed, you would need to enumerate all windows which requires more code.

The ShowWindow command can also be used to restore the Window.

Rifat Bin Reza
  • 2,601
  • 2
  • 14
  • 29
0

Maybe this code will help you, I use it to detect mouse events to minimize the opencv GUI when I click it, obviously, you can create another more interesting application with this:

import cv2
import numpy as np
import win32gui,win32con

a = np.zeros((200,200,3),np.uint8)

def tactil_sec(event,x,y,flags,param):
    if event == cv2.EVENT_LBUTTONDOWN:
        cv2.imshow("LOL",a)
        Minimize = win32gui.GetForegroundWindow()
        win32gui.ShowWindow(Minimize, win32con.SW_MINIMIZE)

cv2.namedWindow('LOL')
cv2.setMouseCallback('LOL',tactil_sec)

while 1:
    cv2.imshow("LOL",a)
    if (cv2.waitKey(20) & 0xFF == 27):
        break

cv2.destroyAllWindows() 
Diroallu
  • 824
  • 1
  • 11
  • 15