[][src]Module opencv::highgui

High-level GUI

While OpenCV was designed for use in full-scale applications and can be used within functionally rich UI frameworks (such as Qt*, WinForms*, or Cocoa*) or without any UI at all, sometimes there it is required to try functionality quickly and visualize the results. This is what the HighGUI module has been designed for.

It provides easy interface to:

  • Create and manipulate windows that can display images and "remember" their content (no need to handle repaint events from OS).
  • Add trackbars to the windows, handle simple mouse events as well as keyboard commands.

OpenGL support

Qt New Functions

image

This figure explains new functionality implemented with Qt* GUI. The new GUI provides a statusbar, a toolbar, and a control panel. The control panel can have trackbars and buttonbars attached to it. If you cannot see the control panel, press Ctrl+P or right-click any Qt window and select Display properties window.

  • To attach a trackbar, the window name parameter must be NULL.

  • To attach a buttonbar, a button must be created. If the last bar attached to the control panel is a buttonbar, the new button is added to the right of the last button. If the last bar attached to the control panel is a trackbar, or the control panel is empty, a new buttonbar is created. Then, a new button is attached to it.

See below the example used to generate the figure:

This example is not tested
int main(int argc, char *argv[])
{

int value = 50;
int value2 = 0;


namedWindow("main1",WINDOW_NORMAL);
namedWindow("main2",WINDOW_AUTOSIZE | CV_GUI_NORMAL);
createTrackbar( "track1", "main1", &value, 255,  NULL);

String nameb1 = "button1";
String nameb2 = "button2";

createButton(nameb1,callbackButton,&nameb1,QT_CHECKBOX,1);
createButton(nameb2,callbackButton,NULL,QT_CHECKBOX,0);
createTrackbar( "track2", NULL, &value2, 255, NULL);
createButton("button5",callbackButton1,NULL,QT_RADIOBOX,0);
createButton("button6",callbackButton2,NULL,QT_RADIOBOX,1);

setMouseCallback( "main2",on_mouse,NULL );

Mat img1 = imread("files/flower.jpg");
VideoCapture video;
video.open("files/hockey.avi");

Mat img2,img3;

while( waitKey(33) != 27 )
{
img1.convertTo(img2,-1,1,value);
video >> img3;

imshow("main1",img2);
imshow("main2",img3);
}

destroyAllWindows();

return 0;
}

WinRT support

This figure explains new functionality implemented with WinRT GUI. The new GUI provides an Image control, and a slider panel. Slider panel holds trackbars attached to it.

Sliders are attached below the image control. Every new slider is added below the previous one.

See below the example used to generate the figure:

This example is not tested
void sample_app::MainPage::ShowWindow()
{
static cv::String windowName("sample");
cv::winrt_initContainer(this->cvContainer);
cv::namedWindow(windowName); // not required

cv::Mat image = cv::imread("Assets/sample.jpg");
cv::Mat converted = cv::Mat(image.rows, image.cols, CV_8UC4);
cv::cvtColor(image, converted, COLOR_BGR2BGRA);
cv::imshow(windowName, converted); // this will create window if it hasn't been created before

int state = 42;
cv::TrackbarCallback callback = [](int pos, void* userdata)
{
if (pos == 0) {
cv::destroyWindow(windowName);
}
};
cv::TrackbarCallback callbackTwin = [](int pos, void* userdata)
{
if (pos >= 70) {
cv::destroyAllWindows();
}
};
cv::createTrackbar("Sample trackbar", windowName, &state, 100, callback);
cv::createTrackbar("Twin brother", windowName, &state, 100, callbackTwin);
}

C API

Structs

QtFont

QtFont available only for Qt. See cv::fontQt

Enums

WindowFlags

Flags for cv::namedWindow

WindowPropertyFlags

Flags for cv::setWindowProperty / cv::getWindowProperty

Constants

EVENT_FLAG_ALTKEY

indicates that ALT Key is pressed.

EVENT_FLAG_CTRLKEY

indicates that CTRL Key is pressed.

EVENT_FLAG_LBUTTON

indicates that the left mouse button is down.

EVENT_FLAG_MBUTTON

indicates that the middle mouse button is down.

EVENT_FLAG_RBUTTON

indicates that the right mouse button is down.

EVENT_FLAG_SHIFTKEY

indicates that SHIFT Key is pressed.

EVENT_LBUTTONDBLCLK

indicates that left mouse button is double clicked.

EVENT_LBUTTONDOWN

indicates that the left mouse button is pressed.

EVENT_LBUTTONUP

indicates that left mouse button is released.

EVENT_MBUTTONDBLCLK

indicates that middle mouse button is double clicked.

EVENT_MBUTTONDOWN

indicates that the middle mouse button is pressed.

EVENT_MBUTTONUP

indicates that middle mouse button is released.

EVENT_MOUSEHWHEEL

positive and negative values mean right and left scrolling, respectively.

EVENT_MOUSEMOVE

indicates that the mouse pointer has moved over the window.

EVENT_MOUSEWHEEL

positive and negative values mean forward and backward scrolling, respectively.

EVENT_RBUTTONDBLCLK

indicates that right mouse button is double clicked.

EVENT_RBUTTONDOWN

indicates that the right mouse button is pressed.

EVENT_RBUTTONUP

indicates that right mouse button is released.

QT_CHECKBOX

Checkbox button.

QT_FONT_BLACK

Weight of 87

QT_FONT_BOLD

Weight of 75

QT_FONT_DEMIBOLD

Weight of 63

QT_FONT_LIGHT

Weight of 25

QT_FONT_NORMAL

Weight of 50

QT_NEW_BUTTONBAR

Button should create a new buttonbar

QT_PUSH_BUTTON

Push button.

QT_RADIOBOX

Radiobox button.

QT_STYLE_ITALIC

Italic font.

QT_STYLE_NORMAL

Normal font.

QT_STYLE_OBLIQUE

Oblique font.

WINDOW_AUTOSIZE

the user cannot resize the window, the size is constrainted by the image displayed.

WINDOW_FREERATIO

the image expends as much as it can (no ratio constraint).

WINDOW_FULLSCREEN

change the window to fullscreen.

WINDOW_GUI_EXPANDED

status bar and tool bar

WINDOW_GUI_NORMAL

old fashious way

WINDOW_KEEPRATIO

the ratio of the image is respected.

WINDOW_NORMAL

the user can resize the window (no constraint) / also use to switch a fullscreen window to a normal size.

WINDOW_OPENGL

window with opengl support.

WND_PROP_ASPECT_RATIO

window's aspect ration (can be set to WINDOW_FREERATIO or WINDOW_KEEPRATIO).

WND_PROP_AUTOSIZE

autosize property (can be WINDOW_NORMAL or WINDOW_AUTOSIZE).

WND_PROP_FULLSCREEN

fullscreen property (can be WINDOW_NORMAL or WINDOW_FULLSCREEN).

WND_PROP_OPENGL

opengl support.

WND_PROP_VISIBLE

checks whether the window exists and is visible

Functions

add_text

Draws a text on the image.

add_text_with_font

Draws a text on the image.

create_button

Attaches a button to the control panel.

create_trackbar

Creates a trackbar and attaches it to the specified window.

destroy_all_windows

Destroys all of the HighGUI windows.

destroy_window

Destroys the specified window.

display_overlay

Displays a text on a window image as an overlay for a specified duration.

display_status_bar

Displays a text on the window statusbar during the specified period of time.

font_qt

Creates the font to draw a text on an image.

get_mouse_wheel_delta

Gets the mouse-wheel motion delta, when handling mouse-wheel events cv::EVENT_MOUSEWHEEL and cv::EVENT_MOUSEHWHEEL.

get_trackbar_pos

Returns the trackbar position.

get_window_image_rect

Provides rectangle of image in the window.

get_window_property

Provides parameters of a window.

imshow

Displays an image in the specified window.

load_window_parameters

Loads parameters of the specified window.

move_window

Moves window to the specified position

named_window

Creates a window.

resize_window

Resizes window to the specified size

resize_window_1

Resizes window to the specified size

save_window_parameters

Saves parameters of the specified window.

select_roi

Selects ROI on the given image. Function creates a window and allows user to select a ROI using mouse. Controls: use space or enter to finish selection, use key c to cancel selection (function will return the zero cv::Rect).

select_roi_for_window

Selects ROI on the given image. Function creates a window and allows user to select a ROI using mouse. Controls: use space or enter to finish selection, use key c to cancel selection (function will return the zero cv::Rect).

select_rois

Selects ROIs on the given image. Function creates a window and allows user to select a ROIs using mouse. Controls: use space or enter to finish current selection and start a new one, use esc to terminate multiple ROI selection process.

set_mouse_callback

Sets mouse handler for the specified window

set_opengl_context

Sets the specified window as current OpenGL context.

set_opengl_draw_callback

Sets a callback function to be called to draw on top of displayed image.

set_trackbar_max

Sets the trackbar maximum position.

set_trackbar_min

Sets the trackbar minimum position.

set_trackbar_pos

Sets the trackbar position.

set_window_property

Changes parameters of a window dynamically.

set_window_title

Updates window title

start_window_thread
stop_loop
update_window

Force window to redraw its context and call draw callback ( See cv::setOpenGlDrawCallback ).

wait_key

Waits for a pressed key.

wait_key_ex

Similar to #waitKey, but returns full key code.

Type Definitions

ButtonCallback

Callback function for a button created by cv::createButton

MouseCallback

Callback function for mouse events. see cv::setMouseCallback

OpenGlDrawCallback

Callback function defined to be called every frame. See cv::setOpenGlDrawCallback

TrackbarCallback

Callback function for Trackbar see cv::createTrackbar