Reputation: 67
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)
Upvotes: 1
Views: 4070
Reputation: 856
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()
Upvotes: 0
Reputation: 2761
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.
Upvotes: 2