[][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

Constants

EVENT_FLAG_ALTKEY
EVENT_FLAG_CTRLKEY
EVENT_FLAG_LBUTTON
EVENT_FLAG_MBUTTON
EVENT_FLAG_RBUTTON
EVENT_FLAG_SHIFTKEY
EVENT_LBUTTONDBLCLK
EVENT_LBUTTONDOWN
EVENT_LBUTTONUP
EVENT_MBUTTONDBLCLK
EVENT_MBUTTONDOWN
EVENT_MBUTTONUP
EVENT_MOUSEHWHEEL
EVENT_MOUSEMOVE
EVENT_MOUSEWHEEL
EVENT_RBUTTONDBLCLK
EVENT_RBUTTONDOWN
EVENT_RBUTTONUP
QT_CHECKBOX
QT_FONT_BLACK
QT_FONT_BOLD
QT_FONT_DEMIBOLD
QT_FONT_LIGHT
QT_FONT_NORMAL
QT_NEW_BUTTONBAR
QT_PUSH_BUTTON
QT_RADIOBOX
QT_STYLE_ITALIC
QT_STYLE_NORMAL
QT_STYLE_OBLIQUE
WINDOW_AUTOSIZE
WINDOW_FREERATIO
WINDOW_FULLSCREEN
WINDOW_GUI_EXPANDED
WINDOW_GUI_NORMAL
WINDOW_KEEPRATIO
WINDOW_NORMAL
WINDOW_OPENGL
WND_PROP_ASPECT_RATIO
WND_PROP_AUTOSIZE
WND_PROP_FULLSCREEN
WND_PROP_OPENGL
WND_PROP_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_open_gl_context

Sets the specified window as current OpenGL context.

set_open_gl_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