Table of Contents

Class Window

Namespace
OpenCvSharp
Assembly
OpenCvSharp.dll

Wrapper of HighGUI window

public class Window : DisposableObject, IDisposable
Inheritance
Window
Implements
Inherited Members

Constructors

Window()

Creates a window with a random name

public Window()

Window(string)

Creates a window

public Window(string name)

Parameters

name string

Name of the window which is used as window identifier and appears in the window caption.

Window(string, Mat)

Creates a window

public Window(string name, Mat image)

Parameters

name string

Name of the window which is used as window identifier and appears in the window caption.

image Mat

Image to be shown.

Window(string, Mat?, WindowFlags)

Creates a window

public Window(string name, Mat? image = null, WindowFlags flags = WindowFlags.AutoSize)

Parameters

name string

Name of the window which is used as window identifier and appears in the window caption.

image Mat

Image to be shown.

flags WindowFlags

Flags of the window. Currently the only supported flag is WindowMode.AutoSize. If it is set, window size is automatically adjusted to fit the displayed image (see cvShowImage), while user can not change the window size manually.

Window(string, WindowFlags)

Creates a window

public Window(string name, WindowFlags flags = WindowFlags.AutoSize)

Parameters

name string

Name of the window which is used as window identifier and appears in the window caption.

flags WindowFlags

Flags of the window. Currently the only supported flag is WindowMode.AutoSize. If it is set, window size is automatically adjusted to fit the displayed image (see cvShowImage), while user can not change the window size manually.

Properties

Image

Gets or sets an image to be shown

public Mat? Image { get; set; }

Property Value

Mat

Name

Gets window name

public string Name { get; }

Property Value

string

Methods

Close()

Destroys this window.

public void Close()

CreateTrackbar(string, TrackbarCallback)

Creates the trackbar and attaches it to this window

public CvTrackbar CreateTrackbar(string trackbarName, TrackbarCallback callback)

Parameters

trackbarName string

Name of created trackbar.

callback TrackbarCallback

the function to be called every time the slider changes the position. This function should be prototyped as void Foo(int);

Returns

CvTrackbar

CreateTrackbar(string, int, int, TrackbarCallback)

Creates the trackbar and attaches it to this window

public CvTrackbar CreateTrackbar(string trackbarName, int initialPos, int max, TrackbarCallback callback)

Parameters

trackbarName string

Name of created trackbar.

initialPos int

The position of the slider

max int

Maximal position of the slider. Minimal position is always 0.

callback TrackbarCallback

the function to be called every time the slider changes the position. This function should be prototyped as void Foo(int);

Returns

CvTrackbar

DestroyAllWindows()

Destroys all the opened HighGUI windows.

public static void DestroyAllWindows()

DisplayOverlay(string, int)

Display text on the window's image as an overlay for delay milliseconds. This is not editing the image's data. The text is display on the top of the image.

public void DisplayOverlay(string text, int delayMs)

Parameters

text string

Overlay text to write on the window’s image

delayMs int

Delay to display the overlay text. If this function is called before the previous overlay text time out, the timer is restarted and the text updated. If this value is zero, the text never disappears.

DisplayStatusBar(string, int)

public void DisplayStatusBar(string text, int delayms)

Parameters

text string

Text to write on the window’s statusbar

delayms int

Delay to display the text. If this function is called before the previous text time out, the timer is restarted and the text updated. If this value is zero, the text never disapers.

DisposeManaged()

Releases managed resources

protected override void DisposeManaged()

GetHandle()

get native window handle (HWND in case of Win32 and Widget in case of X Window)

public nint GetHandle()

Returns

nint

GetProperty(WindowPropertyFlags)

Get Property of the window

public double GetProperty(WindowPropertyFlags propId)

Parameters

propId WindowPropertyFlags

Property identifier

Returns

double

Value of the specified property

GetWindowByName(string)

Retrieves a created window by name

public static Window? GetWindowByName(string name)

Parameters

name string

Returns

Window

Move(int, int)

Sets window position

public void Move(int x, int y)

Parameters

x int

New x coordinate of top-left corner

y int

New y coordinate of top-left corner

Resize(int, int)

Sets window size

public void Resize(int width, int height)

Parameters

width int

New width

height int

New height

SetMouseCallback(MouseCallback, nint)

Sets the callback function for mouse events occuting within the specified window.

public void SetMouseCallback(MouseCallback onMouse, nint userData = 0)

Parameters

onMouse MouseCallback

Reference to the function to be called every time mouse event occurs in the specified window.

userData nint

SetProperty(WindowPropertyFlags, double)

Set Property of the window

public void SetProperty(WindowPropertyFlags propId, double propValue)

Parameters

propId WindowPropertyFlags

Property identifier

propValue double

New value of the specified property

ShowImage(Mat?)

Shows the image in this window

public void ShowImage(Mat? img)

Parameters

img Mat

Image to be shown.

ShowImage(UMat?)

Shows the image in this window

public void ShowImage(UMat? img)

Parameters

img UMat

Image to be shown.

ShowImages(params Mat[])

public static void ShowImages(params Mat[] images)

Parameters

images Mat[]

ShowImages(IEnumerable<Mat>, IEnumerable<string>)

public static void ShowImages(IEnumerable<Mat> images, IEnumerable<string> names)

Parameters

images IEnumerable<Mat>
names IEnumerable<string>

WaitKey(int)

Waits for a pressed key

public static int WaitKey(int delay = 0)

Parameters

delay int

Delay in milliseconds.

Returns

int

Key code

WaitKeyEx(int)

Waits for a pressed key. Similar to #waitKey, but returns full key code. Key code is implementation specific and depends on used backend: QT/GTK/Win32/etc

public static int WaitKeyEx(int delay = 0)

Parameters

delay int

Delay in milliseconds. 0 is the special value that means ”forever”

Returns

int

Returns the code of the pressed key or -1 if no key was pressed before the specified time had elapsed.