cv3.io.Windows
- class cv3.io.Windows(window_names, poses=None)[source]
Bases:
objectA class to manage multiple display windows.
This class provides a convenient way to create and manage multiple OpenCV windows with additional features like context manager support.
- windows
A dictionary mapping window names to Window objects.
- Type:
dict
- __init__(window_names, poses=None)[source]
Initialize a Windows object.
- Parameters:
window_names (list) – List of window names.
poses (list, optional) – List of positions for each window as (x, y) tuples. If None, windows will use default positions. Defaults to None.
Example
>>> import cv3 >>> # Create multiple windows >>> windows = cv3.Windows(['Window1', 'Window2']) >>> # Create multiple windows with specific positions >>> windows = cv3.Windows(['Window1', 'Window2'], poses=[(100, 100), (200, 200)])
- __getitem__(name)[source]
Get a specific window by name.
- Parameters:
name (str) – Name of the window to retrieve.
- Returns:
The requested window object.
- Return type:
Example
>>> import cv3 >>> # Create multiple windows >>> windows = cv3.Windows(['Window1', 'Window2']) >>> # Access a specific window >>> window1 = windows['Window1']
- close()[source]
Close all windows and free associated resources.
Example
>>> import cv3 >>> # Create multiple windows >>> windows = cv3.Windows(['Window1', 'Window2']) >>> # Close all windows >>> windows.close()
- static wait_key(t)[source]
Wait for a keyboard event.
This is a static method that calls the module-level wait_key function.
- Parameters:
t (int) – Delay in milliseconds. If 0, it waits indefinitely for a key stroke.
- Returns:
The code of the pressed key, or -1 if no key was pressed before the timeout.
- Return type:
int
Example
>>> import cv3 >>> # Create multiple windows >>> windows = cv3.Windows(['Window1', 'Window2']) >>> # Wait for a key press for 1 second >>> key = windows.wait_key(1000)
- __enter__()[source]
Enter the runtime context for the windows.
- Returns:
This windows instance.
- Return type:
Example
>>> import cv3 >>> # Use windows as a context manager >>> with cv3.Windows(['Window1', 'Window2']) as windows: ... # All windows are automatically closed when exiting the context ... pass