cvui
A (very) simple UI lib built on top of OpenCV drawing primitives
cvui Namespace Reference

Classes

struct  cvui_block_t
 
struct  cvui_context_t
 
struct  cvui_input_t
 
struct  cvui_label_t
 
struct  cvui_mouse_btn_t
 
struct  cvui_mouse_t
 

Functions

void beginColumn (cv::Mat &theWhere, int theX, int theY, int theWidth=-1, int theHeight=-1, int thePadding=0)
 Start a new column. More...
 
void beginColumn (int theWidth=-1, int theHeight=-1, int thePadding=0)
 Start a column. More...
 
void beginRow (cv::Mat &theWhere, int theX, int theY, int theWidth=-1, int theHeight=-1, int thePadding=0)
 Start a new row. More...
 
void beginRow (int theWidth=-1, int theHeight=-1, int thePadding=0)
 Start a row. More...
 
bool button (const cv::String &theLabel)
 Display a button within a begin*() and end*() block. More...
 
bool button (cv::Mat &theIdle, cv::Mat &theOver, cv::Mat &theDown)
 Display a button whose graphics are images (cv::Mat). More...
 
bool button (cv::Mat &theWhere, int theX, int theY, const cv::String &theLabel)
 Display a button. More...
 
bool button (cv::Mat &theWhere, int theX, int theY, cv::Mat &theIdle, cv::Mat &theOver, cv::Mat &theDown)
 Display a button whose graphics are images (cv::Mat). More...
 
bool button (cv::Mat &theWhere, int theX, int theY, int theWidth, int theHeight, const cv::String &theLabel)
 Display a button. More...
 
bool button (int theWidth, int theHeight, const cv::String &theLabel)
 Display a button within a begin*() and end*() block. More...
 
bool checkbox (const cv::String &theLabel, bool *theState, unsigned int theColor=0xCECECE)
 Display a checkbox within a begin*() and end*() block. More...
 
bool checkbox (cv::Mat &theWhere, int theX, int theY, const cv::String &theLabel, bool *theState, unsigned int theColor=0xCECECE)
 Display a checkbox. More...
 
void context (const cv::String &theWindowName)
 Inform cvui that all subsequent component calls belong to a window in particular. More...
 
double counter (cv::Mat &theWhere, int theX, int theY, double *theValue, double theStep=0.5, const char *theFormat="%.2f")
 Display a counter for float values that the user can increase/descrease by clicking the up and down arrows. More...
 
int counter (cv::Mat &theWhere, int theX, int theY, int *theValue, int theStep=1, const char *theFormat="%d")
 Display a counter for integer values that the user can increase/descrease by clicking the up and down arrows. More...
 
double counter (double *theValue, double theStep=0.5, const char *theFormat="%.2f")
 Display a counter for float values that the user can increase/descrease by clicking the up and down arrows. More...
 
int counter (int *theValue, int theStep=1, const char *theFormat="%d")
 Display a counter for integer values that the user can increase/descrease by clicking the up and down arrows. More...
 
void endColumn ()
 End a column. More...
 
void endRow ()
 Ends a row. More...
 
void handleMouse (int theEvent, int theX, int theY, int theFlags, void *theData)
 
bool headless ()
 Inform if cvui is running in headless more. More...
 
void headless (bool theValue)
 Enable/disable headless more. More...
 
int iarea (int theX, int theY, int theWidth, int theHeight)
 Create an interaction area that reports activity with the mouse cursor. More...
 
void image (cv::Mat &theImage)
 Display an image (cv::Mat) within a begin*() and end*() block. More...
 
void image (cv::Mat &theWhere, int theX, int theY, cv::Mat &theImage)
 Display an image (cv::Mat). More...
 
void imshow (const cv::String &theWindowName, cv::InputArray theFrame)
 Display an image in the specified window and update the internal structures of cvui. More...
 
void init (const cv::String &theWindowName, int theDelayWaitKey=-1, bool theCreateNamedWindow=true, bool theHeadlessMode=false)
 Initializes cvui. More...
 
void init (const cv::String theWindowNames[], size_t theHowManyWindows, int theDelayWaitKey=-1, bool theCreateNamedWindows=true, bool theHeadlessMode=false)
 Initialize cvui using a list of names of windows where components will be added. More...
 
int input (cv::Mat &theWhere, int theX, int theY, int theWidth, const cv::String theName, cv::String &theValue, double theFontScale=0.5)
 Display an inputtext. More...
 
int lastKeyPressed ()
 Return the last key that was pressed. More...
 
bool mouse (const cv::String &theWindowName, int theButton, int theQuery)
 Query the mouse for events in a particular button in a particular window. More...
 
bool mouse (const cv::String &theWindowName, int theQuery)
 Query the mouse for events in a particular window. More...
 
cv::Point mouse (const cv::String &theWindowName="")
 Return the last position of the mouse. More...
 
bool mouse (int theButton, int theQuery)
 Query the mouse for events in a particular button. More...
 
bool mouse (int theQuery)
 Query the mouse for events, e.g. More...
 
void printf (const char *theFmt,...)
 Display a piece of text that can be formated using stdio's printf() style. More...
 
void printf (cv::Mat &theWhere, int theX, int theY, const char *theFmt,...)
 Display a piece of text that can be formated using stdio's printf() style. More...
 
void printf (cv::Mat &theWhere, int theX, int theY, double theFontScale, unsigned int theColor, const char *theFmt,...)
 Display a piece of text that can be formated using stdio's printf() style. More...
 
void printf (double theFontScale, unsigned int theColor, const char *theFmt,...)
 Display a piece of text within a begin*() and end*() block. More...
 
void rect (cv::Mat &theWhere, int theX, int theY, int theWidth, int theHeight, unsigned int theBorderColor, unsigned int theFillingColor=0xff000000)
 Display a filled rectangle. More...
 
void rect (int theWidth, int theHeight, unsigned int theBorderColor, unsigned int theFillingColor=0xff000000)
 Display a rectangle within a begin*() and end*() block. More...
 
void space (int theValue=5)
 Add an arbitrary amount of space between components within a begin*() and end*() block. More...
 
void sparkline (cv::Mat &theWhere, std::vector< double > &theValues, int theX, int theY, int theWidth, int theHeight, unsigned int theColor=0x00FF00)
 Display the values of a vector as a sparkline. More...
 
void sparkline (std::vector< double > &theValues, int theWidth, int theHeight, unsigned int theColor=0x00FF00)
 Display the values of a vector as a sparkline within a begin*() and end*() block. More...
 
void text (const cv::String &theText, double theFontScale=0.4, unsigned int theColor=0xCECECE)
 Display a piece of text within a begin*() and end*() block. More...
 
void text (cv::Mat &theWhere, int theX, int theY, const cv::String &theText, double theFontScale=0.4, unsigned int theColor=0xCECECE)
 Display a piece of text. More...
 
template<typename num_type >
bool trackbar (cv::Mat &theWhere, int theX, int theY, int theWidth, num_type *theValue, num_type theMin, num_type theMax, int theSegments, const char *theLabelFormat, unsigned int theOptions, num_type theDiscreteStep)
 
template<typename T >
bool trackbar (cv::Mat &theWhere, int theX, int theY, int theWidth, T *theValue, T theMin, T theMax, int theSegments=1, const char *theLabelFormat="%.1Lf", unsigned int theOptions=0, T theDiscreteStep=1)
 Display a trackbar for numeric values that the user can increase/decrease by clicking and/or dragging the marker right or left. More...
 
template<typename num_type >
bool trackbar (int theWidth, num_type *theValue, num_type theMin, num_type theMax, int theSegments, const char *theLabelFormat, unsigned int theOptions, num_type theDiscreteStep)
 
template<typename T >
bool trackbar (int theWidth, T *theValue, T theMin, T theMax, int theSegments=1, const char *theLabelFormat="%.1Lf", unsigned int theOptions=0, T theDiscreteStep=1)
 Display a trackbar for numeric values that the user can increase/decrease by clicking and/or dragging the marker right or left. More...
 
void update (const cv::String &theWindowName="")
 Update the library internal things. More...
 
void watch (const cv::String &theWindowName, bool theCreateNamedWindow=true)
 Track UI interactions of a particular window. More...
 
void window (cv::Mat &theWhere, int theX, int theY, int theWidth, int theHeight, const cv::String &theTitle)
 Display a window (a block with a title and a body). More...
 
void window (int theWidth, int theHeight, const cv::String &theTitle)
 Display a window (a block with a title and a body) within a begin*() and end*() block. More...
 

Variables

const int CLICK = 3
 
const int COLUMN = 1
 
const int DOWN = 2
 
const unsigned int INTPUT_CURSOR_BLINK_SLOWNESS = 10
 
const int IS_DOWN = 7
 
const unsigned int KEY_ARROW_DOWN = 2621440
 
const unsigned int KEY_ARROW_LEFT = 2424832
 
const unsigned int KEY_ARROW_RIGHT = 2555904
 
const unsigned int KEY_ARROW_UP = 2490368
 
const unsigned int KEY_BACKSPACE = 8
 
const unsigned int KEY_DELETE = 3014656
 
const unsigned int KEY_END = 2293760
 
const unsigned int KEY_ENTER = 13
 
const unsigned int KEY_HOME = 2359296
 
const unsigned int KEY_NONE = -1
 
const unsigned int KEY_TAB = 9
 
const int LEFT_BUTTON = 0
 
const int MIDDLE_BUTTON = 1
 
const int OUT = 5
 
const int OVER = 4
 
const int RIGHT_BUTTON = 2
 
const int ROW = 0
 
const unsigned int TRACKBAR_DISCRETE = 4
 
const unsigned int TRACKBAR_HIDE_LABELS = 32
 
const unsigned int TRACKBAR_HIDE_MIN_MAX_LABELS = 8
 
const unsigned int TRACKBAR_HIDE_SEGMENT_LABELS = 1
 
const unsigned int TRACKBAR_HIDE_STEP_SCALE = 2
 
const unsigned int TRACKBAR_HIDE_VALUE_LABEL = 16
 
const int UP = 6
 

Function Documentation

◆ beginColumn() [1/2]

void cvui::beginColumn ( cv::Mat &  theWhere,
int  theX,
int  theY,
int  theWidth = -1,
int  theHeight = -1,
int  thePadding = 0 
)

Start a new column.

One of the most annoying tasks when building UI is to calculate where each component should be placed on the screen. cvui has a set of methods that abstract the process of positioning components, so you don't have to think about assigning a X and Y coordinate. Instead you just add components and cvui will place them as you go.

You use beginColumn() to start a group of elements. After beginColumn() has been called, all subsequent component calls don't have to specify the frame where the component should be rendered nor its position. The position of the component will be automatically calculated by cvui based on the components within the group. All components are placed below each other, from the top of the screen towards the bottom.

E.g.

beginColumn(frame, x, y, width, height);
text("test");
button("btn");

Rows and columns can be nested, so you can create columns/rows within columns/rows as much as you want. It's important to notice that any component within beginColumn() and endColumn() do not specify the position where the component is rendered, which is also true for beginColumn(). As a consequence, be sure you are calling beginColumn(width, height) when the call is nested instead of beginColumn(x, y, width, height), otherwise cvui will throw an error.

E.g.

beginColumn(frame, x, y, width, height);
text("test");
button("btn");
beginRow(); // no frame nor x,y parameters here!
text("column1");
text("column2");
endRow();

Don't forget to call endColumn() to finish the column, otherwise cvui will throw an error.

Parameters
theWhereimage/frame where the components within this block should be rendered.
theXposition X where the row should be placed.
theYposition Y where the row should be placed.
theWidthwidth of the column. If a negative value is specified, the width of the column will be automatically calculated based on the content of the block.
theHeightheight of the column. If a negative value is specified, the height of the column will be automatically calculated based on the content of the block.
thePaddingspace, in pixels, among the components of the block.
See also
beginRow()
endColumn()
endRow()

Referenced by EnhancedWindow::begin(), and main().

◆ beginColumn() [2/2]

void cvui::beginColumn ( int  theWidth = -1,
int  theHeight = -1,
int  thePadding = 0 
)

Start a column.

This function behaves in the same way as beginColumn(frame, x, y, width, height), however it is suposed to be used within begin*()/end*() blocks since they require components not to inform frame nor x,y coordinates.

IMPORTANT: this function can only be used within a begin*()/end*() block, otherwise it does nothing.

Parameters
theWidthwidth of the column. If a negative value is specified, the width of the column will be automatically calculated based on the content of the block.
theHeightheight of the column. If a negative value is specified, the height of the column will be automatically calculated based on the content of the block.
thePaddingspace, in pixels, among the components of the block.
See also
beginColumn()
endRow()
endColumn()

Referenced by EnhancedWindow.EnhancedWindow::begin(), multiple-windows-complex::main(), nested-rows-columns::main(), on-image::main(), trackbar-complex::main(), row-column::main(), and multiple-windows-complex-dynamic::main().

◆ beginRow() [1/2]

void cvui::beginRow ( cv::Mat &  theWhere,
int  theX,
int  theY,
int  theWidth = -1,
int  theHeight = -1,
int  thePadding = 0 
)

Start a new row.

One of the most annoying tasks when building UI is to calculate where each component should be placed on the screen. cvui has a set of methods that abstract the process of positioning components, so you don't have to think about assigning a X and Y coordinate. Instead you just add components and cvui will place them as you go.

You use beginRow() to start a group of elements. After beginRow() has been called, all subsequent component calls don't have to specify the frame where the component should be rendered nor its position. The position of the component will be automatically calculated by cvui based on the components within the group. All components are placed side by side, from left to right.

E.g.

beginRow(frame, x, y, width, height);
text("test");
button("btn");

Rows and columns can be nested, so you can create columns/rows within columns/rows as much as you want. It's important to notice that any component within beginRow() and endRow() do not specify the position where the component is rendered, which is also true for beginRow(). As a consequence, be sure you are calling beginRow(width, height) when the call is nested instead of beginRow(x, y, width, height), otherwise cvui will throw an error.

E.g.

beginRow(frame, x, y, width, height);
text("test");
button("btn");
beginColumn(); // no frame nor x,y parameters here!
text("column1");
text("column2");

Don't forget to call endRow() to finish the row, otherwise cvui will throw an error.

Parameters
theWhereimage/frame where the components within this block should be rendered.
theXposition X where the row should be placed.
theYposition Y where the row should be placed.
theWidthwidth of the row. If a negative value is specified, the width of the row will be automatically calculated based on the content of the block.
theHeightheight of the row. If a negative value is specified, the height of the row will be automatically calculated based on the content of the block.
thePaddingspace, in pixels, among the components of the block.
See also
beginColumn()
endRow()
endColumn()

Referenced by EnhancedWindow::begin(), and main().

◆ beginRow() [2/2]

void cvui::beginRow ( int  theWidth = -1,
int  theHeight = -1,
int  thePadding = 0 
)

Start a row.

This function behaves in the same way as beginRow(frame, x, y, width, height), however it is suposed to be used within begin*()/end*() blocks since they require components not to inform frame nor x,y coordinates.

IMPORTANT: this function can only be used within a begin*()/end*() block, otherwise it does nothing.

Parameters
theWidthwidth of the row. If a negative value is specified, the width of the row will be automatically calculated based on the content of the block.
theHeightheight of the row. If a negative value is specified, the height of the row will be automatically calculated based on the content of the block.
thePaddingspace, in pixels, among the components of the block.
See also
beginColumn()
endRow()
endColumn()

Referenced by EnhancedWindow.EnhancedWindow::begin(), multiple-windows-complex::main(), nested-rows-columns::main(), trackbar-sparkline::main(), and row-column::main().

◆ button() [1/6]

bool cvui::button ( const cv::String &  theLabel)

Display a button within a begin*() and end*() block.

The size of the button will be automatically adjusted to properly house the label content.

IMPORTANT: this function can only be used within a begin*()/end*() block, otherwise it does nothing.

Parameters
theLabeltext displayed inside the button. You can set shortcuts by pre-pending them with "&"
Returns
true everytime the user clicks the button.
See also
beginColumn()
beginRow()
endRow()
endColumn()

◆ button() [2/6]

bool cvui::button ( cv::Mat &  theIdle,
cv::Mat &  theOver,
cv::Mat &  theDown 
)

Display a button whose graphics are images (cv::Mat).

IMPORTANT: this function can only be used within a begin*()/end*() block, otherwise it does nothing.

The button accepts three images to describe its states, which are idle (no mouse interaction), over (mouse is over the button) and down (mouse clicked the button). The button size will be defined by the width and height of the images.

Parameters
theIdleimage that will be rendered when the button is not interacting with the mouse cursor.
theOverimage that will be rendered when the mouse cursor is over the button.
theDownimage that will be rendered when the mouse cursor clicked the button (or is clicking).
Returns
true everytime the user clicks the button.
See also
button()
image()
iarea()
beginColumn()
beginRow()
endRow()
endColumn()

Referenced by EnhancedWindow.EnhancedWindow::begin(), multiple-windows::compact(), input-change-counter::main(), input-react-key::main(), input-sizes::main(), image-button::main(), main-app::main(), input-detect-key::main(), input-multiple::main(), hello-world::main(), input::main(), multiple-windows-complex::main(), nested-rows-columns::main(), button-shortcut::main(), trackbar-complex::main(), on-image::main(), trackbar-sparkline::main(), row-column::main(), multiple-windows-complex-dynamic::main(), and multiple-windows::window().

◆ button() [3/6]

bool cvui::button ( cv::Mat &  theWhere,
int  theX,
int  theY,
const cv::String &  theLabel 
)

Display a button.

The size of the button will be automatically adjusted to properly house the label content.

Parameters
theWhereimage/frame where the component should be rendered.
theXposition X where the component should be placed.
theYposition Y where the component should be placed.
theLabeltext displayed inside the button.
Returns
true everytime the user clicks the button.

Referenced by EnhancedWindow::begin(), compact(), main(), and window().

◆ button() [4/6]

bool cvui::button ( cv::Mat &  theWhere,
int  theX,
int  theY,
cv::Mat &  theIdle,
cv::Mat &  theOver,
cv::Mat &  theDown 
)

Display a button whose graphics are images (cv::Mat).

The button accepts three images to describe its states, which are idle (no mouse interaction), over (mouse is over the button) and down (mouse clicked the button). The button size will be defined by the width and height of the images.

Parameters
theWhereimage/frame where the component should be rendered.
theXposition X where the component should be placed.
theYposition Y where the component should be placed.
theIdlean image that will be rendered when the button is not interacting with the mouse cursor.
theOveran image that will be rendered when the mouse cursor is over the button.
theDownan image that will be rendered when the mouse cursor clicked the button (or is clicking).
Returns
true everytime the user clicks the button.
See also
button()
image()
iarea()

◆ button() [5/6]

bool cvui::button ( cv::Mat &  theWhere,
int  theX,
int  theY,
int  theWidth,
int  theHeight,
const cv::String &  theLabel 
)

Display a button.

The button size will be defined by the width and height parameters, no matter the content of the label.

Parameters
theWhereimage/frame where the component should be rendered.
theXposition X where the component should be placed.
theYposition Y where the component should be placed.
theWidthwidth of the button.
theHeightheight of the button.
theLabeltext displayed inside the button.
Returns
true everytime the user clicks the button.

◆ button() [6/6]

bool cvui::button ( int  theWidth,
int  theHeight,
const cv::String &  theLabel 
)

Display a button within a begin*() and end*() block.

The button size will be defined by the width and height parameters, no matter the content of the label.

IMPORTANT: this function can only be used within a begin*()/end*() block, otherwise it does nothing.

Parameters
theWidthwidth of the button.
theHeightheight of the button.
theLabeltext displayed inside the button. You can set shortcuts by pre-pending them with "&"
Returns
true everytime the user clicks the button.
See also
beginColumn()
beginRow()
endRow()
endColumn()

◆ checkbox() [1/2]

bool cvui::checkbox ( const cv::String &  theLabel,
bool *  theState,
unsigned int  theColor = 0xCECECE 
)

Display a checkbox within a begin*() and end*() block.

You can use the state parameter to monitor if the checkbox is checked or not.

IMPORTANT: this function can only be used within a begin*()/end*() block, otherwise it does nothing.

Parameters
theLabeltext displayed besides the clickable checkbox square.
theStatedescribes the current state of the checkbox: true means the checkbox is checked.
theColorcolor of the label in the format 0xRRGGBB, e.g. 0xff0000 for red.
Returns
a boolean value that indicates the current state of the checkbox, true if it is checked.
See also
beginColumn()
beginRow()
endRow()
endColumn()

Referenced by headless::main(), main-app::main(), canny::main(), multiple-windows-complex::main(), ui-enhanced-canny::main(), row-column::main(), and Class1.Class1::renderInfo().

◆ checkbox() [2/2]

bool cvui::checkbox ( cv::Mat &  theWhere,
int  theX,
int  theY,
const cv::String &  theLabel,
bool *  theState,
unsigned int  theColor = 0xCECECE 
)

Display a checkbox.

You can use the state parameter to monitor if the checkbox is checked or not.

Parameters
theWhereimage/frame where the component should be rendered.
theXposition X where the component should be placed.
theYposition Y where the component should be placed.
theLabeltext displayed besides the clickable checkbox square.
theStatedescribes the current state of the checkbox: true means the checkbox is checked.
theColorcolor of the label in the format 0xRRGGBB, e.g. 0xff0000 for red.
Returns
a boolean value that indicates the current state of the checkbox, true if it is checked.

Referenced by main(), and Class1::renderInfo().

◆ context()

void cvui::context ( const cv::String &  theWindowName)

Inform cvui that all subsequent component calls belong to a window in particular.

When using cvui with multiple OpenCV windows, you must call cvui component calls between cvui::contex(NAME) and cvui::update(NAME), where NAME is the name of the window. That way, cvui knows which window you are using (NAME in this case), so it can track mouse events, for instance.

E.g.

// Code for window "window1".
cvui::context("window1");
cvui::text(frame, ...);
cvui::button(frame, ...);
cvui::update("window1");
// somewhere else, code for "window2"
cvui::context("window2");
cvui::printf(frame, ...);
cvui::printf(frame, ...);
cvui::update("window2");
// Show everything in a window
cv::imshow(frame);

Pay attention to the pair cvui::context(NAME) and cvui::update(NAME), which encloses the component calls for that window. You need such pair for each window of your application.

After calling cvui::update(), you can show the result in a window using cv::imshow(). If you want to save some typing, you can use cvui::imshow(), which calls cvui::update() for you and then shows the frame in a window.

E.g.:

// Code for window "window1".
cvui::context("window1");
cvui::text(frame, ...);
cvui::button(frame, ...);
cvui::imshow("window1");
// somewhere else, code for "window2"
cvui::context("window2");
cvui::printf(frame, ...);
cvui::printf(frame, ...);
cvui::imshow("window2");

In that case, you don't have to bother calling cvui::update() yourself, since cvui::imshow() will do it for you.

Parameters
theWindowNamename of the window that will receive components from all subsequent cvui calls.
See also
init()
watch()

Referenced by multiple-windows::compact(), compact(), main(), multiple-windows-complex::main(), multiple-windows-complex-mouse::main(), multiple-windows-complex-dynamic::main(), multiple-windows::window(), and window().

◆ counter() [1/4]

double cvui::counter ( cv::Mat &  theWhere,
int  theX,
int  theY,
double *  theValue,
double  theStep = 0.5,
const char *  theFormat = "%.2f" 
)

Display a counter for float values that the user can increase/descrease by clicking the up and down arrows.

Parameters
theWhereimage/frame where the component should be rendered.
theXposition X where the component should be placed.
theYposition Y where the component should be placed.
theValuethe current value of the counter.
theStepthe amount that should be increased/decreased when the user interacts with the counter buttons
theFormathow the value of the counter should be presented, as it was printed by stdio's printf(). E.g. "%f" means the value will be displayed as a regular float, "%.2f" float with two digits after the point, etc.
Returns
a float that corresponds to the current value of the counter.

◆ counter() [2/4]

int cvui::counter ( cv::Mat &  theWhere,
int  theX,
int  theY,
int *  theValue,
int  theStep = 1,
const char *  theFormat = "%d" 
)

Display a counter for integer values that the user can increase/descrease by clicking the up and down arrows.

Parameters
theWhereimage/frame where the component should be rendered.
theXposition X where the component should be placed.
theYposition Y where the component should be placed.
theValuethe current value of the counter.
theStepthe amount that should be increased/decreased when the user interacts with the counter buttons
theFormathow the value of the counter should be presented, as it was printed by stdio's printf(). E.g. "%d" means the value will be displayed as an integer, "%0d" integer with one leading zero, etc.
Returns
integer that corresponds to the current value of the counter.

Referenced by main().

◆ counter() [3/4]

double cvui::counter ( double *  theValue,
double  theStep = 0.5,
const char *  theFormat = "%.2f" 
)

Display a counter for float values that the user can increase/descrease by clicking the up and down arrows.

IMPORTANT: this function can only be used within a begin*()/end*() block, otherwise it does nothing.

Parameters
theValuethe current value of the counter.
theStepthe amount that should be increased/decreased when the user interacts with the counter buttons.
theFormathow the value of the counter should be presented, as it was printed by stdio's printf(). E.g. "%d" means the value will be displayed as an integer, "%0d" integer with one leading zero, etc.
Returns
an float that corresponds to the current value of the counter.
See also
printf()
beginColumn()
beginRow()
endRow()
endColumn()

Referenced by input-change-counter::main(), main-app::main(), multiple-windows-complex::main(), and row-column::main().

◆ counter() [4/4]

int cvui::counter ( int *  theValue,
int  theStep = 1,
const char *  theFormat = "%d" 
)

Display a counter for integer values that the user can increase/descrease by clicking the up and down arrows.

IMPORTANT: this function can only be used within a begin*()/end*() block, otherwise it does nothing.

Parameters
theValuethe current value of the counter.
theStepthe amount that should be increased/decreased when the user interacts with the counter buttons.
theFormathow the value of the counter should be presented, as it was printed by stdio's printf(). E.g. "%d" means the value will be displayed as an integer, "%0d" integer with one leading zero, etc.
Returns
integer that corresponds to the current value of the counter.
See also
printf()
beginColumn()
beginRow()
endRow()
endColumn()

◆ endColumn()

◆ endRow()

void cvui::endRow ( )

Ends a row.

You must call this function only if you have previously called its counter part, the beginRow() function.

See also
beginRow()
beginColumn()
endColumn()

Referenced by EnhancedWindow.EnhancedWindow::end(), EnhancedWindow::end(), multiple-windows-complex::main(), main(), nested-rows-columns::main(), trackbar-sparkline::main(), and row-column::main().

◆ handleMouse()

void cvui::handleMouse ( int  theEvent,
int  theX,
int  theY,
int  theFlags,
void *  theData 
)

◆ headless() [1/2]

bool cvui::headless ( )

Inform if cvui is running in headless more.

Returns
true if running in headless mode, or false otherwise.
See also
init()

◆ headless() [2/2]

void cvui::headless ( bool  theValue)

Enable/disable headless more.

When running in headless mode, cvui will not render anything to the screen and it will not process interactions such as mouse clicks. This mode is useful to test apps in CI/CD.

Parameters
theValuetrue if cvui should run in headless more, false otherwise.
See also
init()

◆ iarea()

int cvui::iarea ( int  theX,
int  theY,
int  theWidth,
int  theHeight 
)

Create an interaction area that reports activity with the mouse cursor.

The tracked interactions are returned by the function and they are:

OUT when the cursor is not over the iarea. OVER when the cursor is over the iarea. DOWN when the cursor is pressed over the iarea, but not released yet. CLICK when the cursor clicked (pressed and released) within the iarea.

This function creates no visual output on the screen. It is intended to be used as an auxiliary tool to create interactions.

Parameters
theXposition X where the interactive area should be placed.
theYposition Y where the interactive area should be placed.
theWidthwidth of the interactive area.
theHeightheight of the interactive area.
Returns
integer value representing the current state of interaction with the mouse cursor. It can be OUT (cursor is not over the area), OVER (cursor is over the area), DOWN (cursor is pressed over the area, but not released yet) and CLICK (cursor clicked, i.e. pressed and released, within the area).
See also
button()
image()

Referenced by interaction-area::main(), and main().

◆ image() [1/2]

void cvui::image ( cv::Mat &  theImage)

Display an image (cv::Mat) within a begin*() and end*() block.

IMPORTANT: this function can only be used within a begin*()/end*() block, otherwise it does nothing.

Parameters
theImageimage to be rendered in the specified destination.
See also
button()
iarea()
beginColumn()
beginRow()
endRow()
endColumn()

Referenced by multiple-windows-complex::main(), and row-column::main().

◆ image() [2/2]

void cvui::image ( cv::Mat &  theWhere,
int  theX,
int  theY,
cv::Mat &  theImage 
)

Display an image (cv::Mat).

Parameters
theWhereimage/frame where the provded image should be rendered.
theXposition X where the image should be placed.
theYposition Y where the image should be placed.
theImageimage to be rendered in the specified destination.
See also
button()
iarea()

Referenced by main().

◆ imshow()

void cvui::imshow ( const cv::String &  theWindowName,
cv::InputArray  theFrame 
)

Display an image in the specified window and update the internal structures of cvui.

This function can be used as a replacement for cv::imshow(). If you want to use cv::imshow() instead ofcvui::imshow(), you must ensure you callcvui::update() after* all component calls and *before*cv::imshow()`, so cvui can update its internal structures.

In general, it is easier to call cvui::imshow() alone instead of calling ‘cvui::update()’ immediately followed by cv::imshow().

Parameters
theWindowNamename of the window that will be shown.
theFrameimage, i.e. cv::Mat, to be shown in the window.
See also
update()
context()
watch()

Referenced by multiple-windows::compact(), compact(), headless::main(), hello-world::main(), mouse::main(), main(), multiple-windows-complex-mouse::main(), ui-enhanced-window-component::main(), multiple-windows::window(), and window().

◆ init() [1/2]

void cvui::init ( const cv::String &  theWindowName,
int  theDelayWaitKey = -1,
bool  theCreateNamedWindow = true,
bool  theHeadlessMode = false 
)

Initializes cvui.

You must provide the name of the window where components will be added. It is also possible to tell cvui to handle OpenCV's event queue automatically (by informing a value greater than zero in the theDelayWaitKey parameter of the function). In that case, cvui will automatically call cv::waitKey() within cvui::update(), so you don't have to worry about it. The value passed to theDelayWaitKey will be used as the delay for cv::waitKey().

Parameters
theWindowNamename of the window where the components will be added.
theDelayWaitKeydelay value passed to cv::waitKey(). If a negative value is informed (default is -1), cvui will not automatically call cv::waitKey() within cvui::update(), which will disable keyboard shortcuts for all components. If you want to enable keyboard shortcut for components (e.g. using & in a button label), you must specify a positive value for this param.
theCreateNamedWindowif an OpenCV window named theWindowName should be created during the initialization. Windows are created using cv::namedWindow(). If this parameter is false, ensure you call cv::namedWindow(WINDOW_NAME) before initializing cvui, otherwise it will not be able to track UI interactions.
theHeadlessModeif cvui should run in headless more (no rendering or processing of interactions, useful for CI testing).
See also
watch()
context()

Referenced by main().

◆ init() [2/2]

void cvui::init ( const cv::String  theWindowNames[],
size_t  theHowManyWindows,
int  theDelayWaitKey = -1,
bool  theCreateNamedWindows = true,
bool  theHeadlessMode = false 
)

Initialize cvui using a list of names of windows where components will be added.

It is also possible to tell cvui to handle OpenCV's event queue automatically (by informing a value greater than zero in the theDelayWaitKey parameter of the function). In that case, cvui will automatically call cv::waitKey() within cvui::update(), so you don't have to worry about it. The value passed to theDelayWaitKey will be used as the delay for cv::waitKey().

Parameters
theWindowNamesarray containing the name of the windows where components will be added. Those windows will be automatically if theCreateNamedWindows is true.
theHowManyWindowshow many window names exist in the theWindowNames array.
theDelayWaitKeydelay value passed to cv::waitKey(). If a negative value is informed (default is -1), cvui will not automatically call cv::waitKey() within cvui::update(), which will disable keyboard shortcuts for all components. If you want to enable keyboard shortcut for components (e.g. using & in a button label), you must specify a positive value for this param.
theCreateNamedWindowsif OpenCV windows named according to theWindowNames should be created during the initialization. Windows are created using cv::namedWindow(). If this parameter is false, ensure you call cv::namedWindow(WINDOW_NAME) for all windows before initializing cvui, otherwise it will not be able to track UI interactions.
theHeadlessModeif cvui should run in headless more (no rendering or processing of interactions, useful for CI testing).
See also
watch()
context()

Referenced by input-change-counter::main(), input-detect-key::main(), input-multiple::main(), input-react-key::main(), input-sizes::main(), headless::main(), image-button::main(), main-app::main(), mouse::main(), canny::main(), hello-world::main(), mouse-complex::main(), multiple-windows-complex::main(), input::main(), interaction-area::main(), multiple-windows-complex-mouse::main(), nested-rows-columns::main(), mouse-complex-buttons::main(), multiple-files::main(), button-shortcut::main(), trackbar-sparkline::main(), trackbar::main(), on-image::main(), trackbar-complex::main(), ui-enhanced-window-component::main(), ui-enhanced-canny::main(), row-column::main(), sparkline::main(), multiple-windows-complex-dynamic::main(), complex-layout::main(), and multiple-windows::main().

◆ input()

int cvui::input ( cv::Mat &  theWhere,
int  theX,
int  theY,
int  theWidth,
const cv::String  theName,
cv::String &  theValue,
double  theFontScale = 0.5 
)

Display an inputtext.

Parameters
theWhereimage/frame where the provided input should be rendered.
theXposition X where the input should be placed.
theYposition Y where the input should be placed.
theWidthsize, in pixels, of the input.
theNameunique name of the input. It will be used to control focus.
theValuecontent of the input.
theFontScalesize of the text.
See also
button()
counter()

Referenced by input-change-counter::main(), input-detect-key::main(), input-react-key::main(), input-sizes::main(), input-multiple::main(), input::main(), and main().

◆ lastKeyPressed()

int cvui::lastKeyPressed ( )

Return the last key that was pressed.

This function will only work if a value greater than zero was passed to cvui::init() as the delay waitkey parameter.

See also
init()

◆ mouse() [1/5]

bool cvui::mouse ( const cv::String &  theWindowName,
int  theButton,
int  theQuery 
)

Query the mouse for events in a particular button in a particular window.

This function behave exactly like cvui::mouse(int theButton, int theQuery), with the difference that queries are targeted at a particular mouse button in a particular window instead.

Parameters
theWindowNamename of the window that will be queried.
theButtoninteger describing the mouse button to be queried. Possible values are cvui::LEFT_BUTTON, cvui::MIDDLE_BUTTON and cvui::LEFT_BUTTON.
theQueryinteger describing the intended mouse query. Available queries are cvui::DOWN, cvui::UP, cvui::CLICK, and cvui::IS_DOWN.

Referenced by EnhancedWindow.EnhancedWindow::begin(), mouse::main(), interaction-area::main(), mouse-complex::main(), multiple-windows-complex-mouse::main(), and mouse-complex-buttons::main().

◆ mouse() [2/5]

bool cvui::mouse ( const cv::String &  theWindowName,
int  theQuery 
)

Query the mouse for events in a particular window.

This function behave exactly like cvui::mouse(int theQuery) with the difference that queries are targeted at a particular window.

Parameters
theWindowNamename of the window that will be queried.
theQueryinteger describing the intended mouse query. Available queries are cvui::DOWN, cvui::UP, cvui::CLICK, and cvui::IS_DOWN.
See also
mouse(const cv::String&)
mouse(const cv::String&, int, int)
mouse(int, int)
mouse(int)

◆ mouse() [3/5]

cv::Point cvui::mouse ( const cv::String &  theWindowName = "")

Return the last position of the mouse.

Parameters
theWindowNamename of the window whose mouse cursor will be used. If nothing is informed (default), the function will return the position of the mouse cursor for the default window (the one informed in cvui::init()).
Returns
a point containing the position of the mouse cursor in the speficied window.

Referenced by EnhancedWindow::begin(), and main().

◆ mouse() [4/5]

bool cvui::mouse ( int  theButton,
int  theQuery 
)

Query the mouse for events in a particular button.

This function behave exactly like cvui::mouse(int theQuery), with the difference that queries are targeted at a particular mouse button instead.

Parameters
theButtoninteger describing the mouse button to be queried. Possible values are cvui::LEFT_BUTTON, cvui::MIDDLE_BUTTON and cvui::LEFT_BUTTON.
theQueryinteger describing the intended mouse query. Available queries are cvui::DOWN, cvui::UP, cvui::CLICK, and cvui::IS_DOWN.
See also
mouse(const cv::String&)
mouse(const cv::String&, int, int)
mouse(int)

◆ mouse() [5/5]

bool cvui::mouse ( int  theQuery)

Query the mouse for events, e.g.

"is any button down now?". Available queries are:

cvui::DOWN: any mouse button was pressed. cvui::mouse() returns true for a single frame only. cvui::UP: any mouse button was released. cvui::mouse() returns true for a single frame only. cvui::CLICK: any mouse button was clicked (went down then up, no matter the amount of frames in between). cvui::mouse() returns true for a single frame only. cvui::IS_DOWN: any mouse button is currently pressed. cvui::mouse() returns true for as long as the button is down/pressed.

It is easier to think of this function as the answer to a questions. For instance, asking if any mouse button went down:

// Any mouse button just went down.
}

The window whose mouse will be queried depends on the context. If cvui::mouse(query) is being called after cvui::context(), the window informed in the context will be queried. If no context is available, the default window (informed in cvui::init()) will be used.

Parameters
theQueryinteger describing the intended mouse query. Available queries are cvui::DOWN, cvui::UP, cvui::CLICK, and cvui::IS_DOWN.
See also
mouse(const cv::String&)
mouse(const cv::String&, int)
mouse(const cv::String&, int, int)
mouse(int, int)

◆ printf() [1/4]

void cvui::printf ( const char *  theFmt,
  ... 
)

Display a piece of text that can be formated using stdio's printf() style.

IMPORTANT: this function can only be used within a begin*()/end*() block, otherwise it does nothing.

For instance if you want to display text mixed with numbers, you can use:

printf(frame, 10, 15, 0.4, 0xff0000, "Text: %d and %f", 7, 3.1415);

The size and color of the text will be based on cvui's default values.

Parameters
theFmtformating string as it would be supplied for stdio's printf(), e.g. "Text: %d and %f", 7, 3.1415.
See also
text()
beginColumn()
beginRow()
endRow()
endColumn()

Referenced by multiple-windows::compact(), input-change-counter::main(), input-react-key::main(), input-detect-key::main(), main-app::main(), hello-world::main(), mouse::main(), multiple-windows-complex::main(), mouse-complex::main(), interaction-area::main(), multiple-windows-complex-mouse::main(), mouse-complex-buttons::main(), on-image::main(), row-column::main(), and multiple-windows::window().

◆ printf() [2/4]

void cvui::printf ( cv::Mat &  theWhere,
int  theX,
int  theY,
const char *  theFmt,
  ... 
)

Display a piece of text that can be formated using stdio's printf() style.

For instance if you want to display text mixed with numbers, you can use:

printf(frame, 10, 15, 0.4, 0xff0000, "Text: %d and %f", 7, 3.1415);

The size and color of the text will be based on cvui's default values.

Parameters
theWhereimage/frame where the component should be rendered.
theXposition X where the component should be placed.
theYposition Y where the component should be placed.
theFmtformating string as it would be supplied for stdio's printf(), e.g. "Text: %d and %f", 7, 3.1415.
See also
text()

◆ printf() [3/4]

void cvui::printf ( cv::Mat &  theWhere,
int  theX,
int  theY,
double  theFontScale,
unsigned int  theColor,
const char *  theFmt,
  ... 
)

Display a piece of text that can be formated using stdio's printf() style.

For instance if you want to display text mixed with numbers, you can use:

printf(frame, 10, 15, 0.4, 0xff0000, "Text: %d and %f", 7, 3.1415);
Parameters
theWhereimage/frame where the component should be rendered.
theXposition X where the component should be placed.
theYposition Y where the component should be placed.
theFontScalesize of the text.
theColorcolor of the text in the format 0xRRGGBB, e.g. 0xff0000 for red.
theFmtformating string as it would be supplied for stdio's printf(), e.g. "Text: %d and %f", 7, 3.1415.
See also
text()

Referenced by compact(), main(), and window().

◆ printf() [4/4]

void cvui::printf ( double  theFontScale,
unsigned int  theColor,
const char *  theFmt,
  ... 
)

Display a piece of text within a begin*() and end*() block.

IMPORTANT: this function can only be used within a begin*()/end*() block, otherwise it does nothing.

The text can be formated using stdio's printf() style. For instance if you want to display text mixed with numbers, you can use:

printf(0.4, 0xff0000, "Text: %d and %f", 7, 3.1415);
Parameters
theFontScalesize of the text.
theColorcolor of the text in the format 0xRRGGBB, e.g. 0xff0000 for red.
theFmtformating string as it would be supplied for stdio's printf(), e.g. "Text: %d and %f", 7, 3.1415.
See also
text()
beginColumn()
beginRow()
endRow()
endColumn()

◆ rect() [1/2]

void cvui::rect ( cv::Mat &  theWhere,
int  theX,
int  theY,
int  theWidth,
int  theHeight,
unsigned int  theBorderColor,
unsigned int  theFillingColor = 0xff000000 
)

Display a filled rectangle.

Parameters
theWhereimage/frame where the component should be rendered.
theXposition X where the component should be placed.
theYposition Y where the component should be placed.
theWidthwidth of the rectangle.
theHeightheight of the rectangle.
theBorderColorcolor of rectangle's border in the format 0xRRGGBB, e.g. 0xff0000 for red.
theFillingColorcolor of rectangle's filling in the format 0xAARRGGBB, e.g. 0x00ff0000 for red, 0xff000000 for transparent filling.
See also
image()

Referenced by group(), and main().

◆ rect() [2/2]

void cvui::rect ( int  theWidth,
int  theHeight,
unsigned int  theBorderColor,
unsigned int  theFillingColor = 0xff000000 
)

Display a rectangle within a begin*() and end*() block.

IMPORTANT: this function can only be used within a begin*()/end*() block, otherwise it does nothing.

Parameters
theWidthwidth of the rectangle.
theHeightheight of the rectangle.
theBorderColorcolor of rectangle's border in the format 0xRRGGBB, e.g. 0xff0000 for red.
theFillingColorcolor of rectangle's filling in the format 0xAARRGGBB, e.g. 0x00ff0000 for red, 0xff000000 for transparent filling.
See also
window()
beginColumn()
beginRow()
endRow()
endColumn()

Referenced by complex-layout::group(), mouse::main(), mouse-complex::main(), interaction-area::main(), multiple-windows-complex::main(), mouse-complex-buttons::main(), and row-column::main().

◆ space()

void cvui::space ( int  theValue = 5)

Add an arbitrary amount of space between components within a begin*() and end*() block.

The function is aware of context, so if it is used within a beginColumn() and endColumn() block, the space will be vertical. If it is used within a beginRow() and endRow() block, space will be horizontal.

IMPORTANT: this function can only be used within a begin*()/end*() block, otherwise it does nothing.

Parameters
theValuethe amount of space to be added.
See also
beginColumn()
beginRow()
endRow()
endColumn()

Referenced by main(), multiple-windows-complex::main(), nested-rows-columns::main(), on-image::main(), trackbar-complex::main(), ui-enhanced-window-component::main(), ui-enhanced-canny::main(), and row-column::main().

◆ sparkline() [1/2]

void cvui::sparkline ( cv::Mat &  theWhere,
std::vector< double > &  theValues,
int  theX,
int  theY,
int  theWidth,
int  theHeight,
unsigned int  theColor = 0x00FF00 
)

Display the values of a vector as a sparkline.

Parameters
theWhereimage/frame where the component should be rendered.
theValuesa vector containing the values to be used in the sparkline.
theXposition X where the component should be placed.
theYposition Y where the component should be placed.
theWidthwidth of the sparkline.
theHeightheight of the sparkline.
theColorcolor of sparkline in the format 0xRRGGBB, e.g. 0xff0000 for red.
See also
trackbar()

Referenced by main().

◆ sparkline() [2/2]

void cvui::sparkline ( std::vector< double > &  theValues,
int  theWidth,
int  theHeight,
unsigned int  theColor = 0x00FF00 
)

Display the values of a vector as a sparkline within a begin*() and end*() block.

IMPORTANT: this function can only be used within a begin*()/end*() block, otherwise it does nothing.

Parameters
theValuesvector with the values that will be rendered as a sparkline.
theWidthwidth of the sparkline.
theHeightheight of the sparkline.
theColorcolor of sparkline in the format 0xRRGGBB, e.g. 0xff0000 for red.
See also
beginColumn()
beginRow()
endRow()
endColumn()

Referenced by multiple-windows-complex::main(), trackbar-sparkline::main(), row-column::main(), and sparkline::main().

◆ text() [1/2]

void cvui::text ( const cv::String &  theText,
double  theFontScale = 0.4,
unsigned int  theColor = 0xCECECE 
)

Display a piece of text within a begin*() and end*() block.

IMPORTANT: this function can only be used within a begin*()/end*() block, otherwise it does nothing.

Parameters
theTexttext content.
theFontScalesize of the text.
theColorcolor of the text in the format 0xRRGGBB, e.g. 0xff0000 for red.
See also
printf()
beginColumn()
beginRow()
endRow()
endColumn()

Referenced by complex-layout::group(), headless::main(), main-app::main(), image-button::main(), input-multiple::main(), input-sizes::main(), mouse::main(), input::main(), mouse-complex::main(), multiple-windows-complex::main(), mouse-complex-buttons::main(), nested-rows-columns::main(), trackbar::main(), trackbar-complex::main(), trackbar-sparkline::main(), button-shortcut::main(), ui-enhanced-window-component::main(), ui-enhanced-canny::main(), row-column::main(), multiple-windows-complex-dynamic::main(), and Class2.Class2::renderMessage().

◆ text() [2/2]

void cvui::text ( cv::Mat &  theWhere,
int  theX,
int  theY,
const cv::String &  theText,
double  theFontScale = 0.4,
unsigned int  theColor = 0xCECECE 
)

Display a piece of text.

Parameters
theWhereimage/frame where the component should be rendered.
theXposition X where the component should be placed.
theYposition Y where the component should be placed.
theTextthe text content.
theFontScalesize of the text.
theColorcolor of the text in the format 0xRRGGBB, e.g. 0xff0000 for red.
See also
printf()

Referenced by group(), main(), and Class2::renderMessage().

◆ trackbar() [1/4]

template<typename num_type >
bool cvui::trackbar ( cv::Mat &  theWhere,
int  theX,
int  theY,
int  theWidth,
num_type *  theValue,
num_type  theMin,
num_type  theMax,
int  theSegments,
const char *  theLabelFormat,
unsigned int  theOptions,
num_type  theDiscreteStep 
)

◆ trackbar() [2/4]

template<typename T >
bool cvui::trackbar ( cv::Mat &  theWhere,
int  theX,
int  theY,
int  theWidth,
T *  theValue,
theMin,
theMax,
int  theSegments = 1,
const char *  theLabelFormat = "%.1Lf",
unsigned int  theOptions = 0,
theDiscreteStep = 1 
)

Display a trackbar for numeric values that the user can increase/decrease by clicking and/or dragging the marker right or left.

This component uses templates so it is imperative that you make it very explicit the type of theValue, theMin, theMax and theStep, otherwise you might end up with weird compilation errors.

Example:

// using double
trackbar(where, x, y, width, &doubleValue, 0.0, 50.0);
// using float
trackbar(where, x, y, width, &floatValue, 0.0f, 50.0f);
// using char
trackbar(where, x, y, width, &charValue, (char)1, (char)10);
Parameters
theWhereimage/frame where the component should be rendered.
theXposition X where the component should be placed.
theYposition Y where the component should be placed.
theWidththe width of the trackbar.
theValuethe current value of the trackbar. It will be modified when the user interacts with the trackbar. Any numeric type can be used, e.g. float, double, long double, int, char, uchar.
theMinminimum value allowed for the trackbar.
theMaxmaximum value allowed for the trackbar.
theSegmentsnumber of segments the trackbar will have (default is 1). Segments can be seen as groups of numbers in the scale of the trackbar. For example, 1 segment means a single groups of values (no extra labels along the scale), 2 segments mean the trackbar values will be divided in two groups and a label will be placed at the middle of the scale.
theLabelFormatformating string that will be used to render the labels, e.g. %.2Lf (Lf not lf). No matter the type of the theValue param, internally trackbar stores it as a long double, so the formating string will *always receive a long double value to format. If you are using a trackbar with integers values, for instance, you can supress decimals using a formating string such as %.0Lf to format your labels.
theOptionsoptions to customize the behavior/appearance of the trackbar, expressed as a bitset. Available options are defined as TRACKBAR_ constants and they can be combined using the bitwise | operand. Available options are: TRACKBAR_HIDE_SEGMENT_LABELS (do not render segment labels, but do render min/max labels), TRACKBAR_HIDE_STEP_SCALE (do not render the small lines indicating values in the scale), TRACKBAR_DISCRETE (changes of the trackbar value are multiples of theDiscreteStep param), TRACKBAR_HIDE_MIN_MAX_LABELS (do not render min/max labels), TRACKBAR_HIDE_VALUE_LABEL (do not render the current value of the trackbar below the moving marker), TRACKBAR_HIDE_LABELS (do not render labels at all).
theDiscreteStepamount that the trackbar marker will increase/decrease when the marker is dragged right/left (if option TRACKBAR_DISCRETE is ON)
Returns
true when the value of the trackbar changed.
See also
counter()

Referenced by main().

◆ trackbar() [3/4]

template<typename num_type >
bool cvui::trackbar ( int  theWidth,
num_type *  theValue,
num_type  theMin,
num_type  theMax,
int  theSegments,
const char *  theLabelFormat,
unsigned int  theOptions,
num_type  theDiscreteStep 
)

◆ trackbar() [4/4]

template<typename T >
bool cvui::trackbar ( int  theWidth,
T *  theValue,
theMin,
theMax,
int  theSegments = 1,
const char *  theLabelFormat = "%.1Lf",
unsigned int  theOptions = 0,
theDiscreteStep = 1 
)

Display a trackbar for numeric values that the user can increase/decrease by clicking and/or dragging the marker right or left.

IMPORTANT: this function can only be used within a begin*()/end*() block, otherwise it does nothing.

This component uses templates so it is imperative that you make it very explicit the type of theValue, theMin, theMax and theStep, otherwise you might end up with weird compilation errors.

Example:

// using double
trackbar(width, &doubleValue, 0.0, 50.0);
// using float
trackbar(width, &floatValue, 0.0f, 50.0f);
// using char
trackbar(width, &charValue, (char)1, (char)10);
Parameters
theWidththe width of the trackbar.
theValuethe current value of the trackbar. It will be modified when the user interacts with the trackbar. Any numeric type can be used, e.g. float, double, long double, int, char, uchar.
theMinminimum value allowed for the trackbar.
theMaxmaximum value allowed for the trackbar.
theSegmentsnumber of segments the trackbar will have (default is 1). Segments can be seen as groups of numbers in the scale of the trackbar. For example, 1 segment means a single groups of values (no extra labels along the scale), 2 segments mean the trackbar values will be divided in two groups and a label will be placed at the middle of the scale.
theLabelFormatformating string that will be used to render the labels, e.g. %.2Lf. No matter the type of the theValue param, internally trackbar stores it as a long double, so the formating string will always receive a long double value to format. If you are using a trackbar with integers values, for instance, you can supress decimals using a formating string as %.0Lf to format your labels.
theOptionsoptions to customize the behavior/appearance of the trackbar, expressed as a bitset. Available options are defined as TRACKBAR_ constants and they can be combined using the bitwise | operand. Available options are: TRACKBAR_HIDE_SEGMENT_LABELS (do not render segment labels, but do render min/max labels), TRACKBAR_HIDE_STEP_SCALE (do not render the small lines indicating values in the scale), TRACKBAR_DISCRETE (changes of the trackbar value are multiples of informed step param), TRACKBAR_HIDE_MIN_MAX_LABELS (do not render min/max labels), TRACKBAR_HIDE_VALUE_LABEL (do not render the current value of the trackbar below the moving marker), TRACKBAR_HIDE_LABELS (do not render labels at all).
theDiscreteStepthe amount that the trackbar marker will increase/decrease when the marker is dragged right/left (if option TRACKBAR_DISCRETE is ON)
Returns
true when the value of the trackbar changed.
See also
counter()
beginColumn()
beginRow()
endRow()
endColumn()

◆ update()

void cvui::update ( const cv::String &  theWindowName = "")

◆ watch()

void cvui::watch ( const cv::String &  theWindowName,
bool  theCreateNamedWindow = true 
)

Track UI interactions of a particular window.

This function must be invoked for any window that will receive cvui components. cvui automatically calls cvui::watch() for any window informed in cvui::init(), so generally you don't have to watch them yourself. If you initialized cvui and told it not to create windows automatically, you need to call cvui::watch() on those windows yourself. cvui::watch() can automatically create a window before watching it, if it does not exist.

Parameters
theWindowNamename of the window whose UI interactions will be tracked.
theCreateNamedWindowif an OpenCV window named theWindowName should be created before it is watched. Windows are created using cv::namedWindow(). If this parameter is false, ensure you have called cv::namedWindow(WINDOW_NAME) to create the window, otherwise cvui will not be able to track its UI interactions.
See also
init()
context()

Referenced by main(), multiple-windows-complex::main(), multiple-windows-complex-dynamic::main(), multiple-windows-complex-dynamic::openWindow(), and openWindow().

◆ window() [1/2]

void cvui::window ( cv::Mat &  theWhere,
int  theX,
int  theY,
int  theWidth,
int  theHeight,
const cv::String &  theTitle 
)

Display a window (a block with a title and a body).

Parameters
theWhereimage/frame where the component should be rendered.
theXposition X where the component should be placed.
theYposition Y where the component should be placed.
theWidthwidth of the window.
theHeightheight of the window.
theTitletext displayed as the title of the window.
See also
rect()

Referenced by EnhancedWindow::begin(), group(), main(), and Class1::renderInfo().

◆ window() [2/2]

void cvui::window ( int  theWidth,
int  theHeight,
const cv::String &  theTitle 
)

Display a window (a block with a title and a body) within a begin*() and end*() block.

IMPORTANT: this function can only be used within a begin*()/end*() block, otherwise it does nothing.

Parameters
theWidthwidth of the window.
theHeightheight of the window.
theTitletext displayed as the title of the window.
See also
rect()
beginColumn()
beginRow()
endRow()
endColumn()

Referenced by EnhancedWindow.EnhancedWindow::begin(), complex-layout::group(), main-app::main(), canny::main(), multiple-windows-complex::main(), on-image::main(), row-column::main(), and Class1.Class1::renderInfo().

Variable Documentation

◆ CLICK

const int cvui::CLICK = 3

Referenced by main().

◆ COLUMN

const int cvui::COLUMN = 1

◆ DOWN

const int cvui::DOWN = 2

Referenced by EnhancedWindow::begin(), and main().

◆ INTPUT_CURSOR_BLINK_SLOWNESS

const unsigned int cvui::INTPUT_CURSOR_BLINK_SLOWNESS = 10

◆ IS_DOWN

const int cvui::IS_DOWN = 7

Referenced by EnhancedWindow::begin(), and main().

◆ KEY_ARROW_DOWN

const unsigned int cvui::KEY_ARROW_DOWN = 2621440

◆ KEY_ARROW_LEFT

const unsigned int cvui::KEY_ARROW_LEFT = 2424832

◆ KEY_ARROW_RIGHT

const unsigned int cvui::KEY_ARROW_RIGHT = 2555904

◆ KEY_ARROW_UP

const unsigned int cvui::KEY_ARROW_UP = 2490368

◆ KEY_BACKSPACE

const unsigned int cvui::KEY_BACKSPACE = 8

◆ KEY_DELETE

const unsigned int cvui::KEY_DELETE = 3014656

◆ KEY_END

const unsigned int cvui::KEY_END = 2293760

◆ KEY_ENTER

const unsigned int cvui::KEY_ENTER = 13

Referenced by main().

◆ KEY_HOME

const unsigned int cvui::KEY_HOME = 2359296

◆ KEY_NONE

const unsigned int cvui::KEY_NONE = -1

◆ KEY_TAB

const unsigned int cvui::KEY_TAB = 9

◆ LEFT_BUTTON

const int cvui::LEFT_BUTTON = 0

Referenced by main().

◆ MIDDLE_BUTTON

const int cvui::MIDDLE_BUTTON = 1

◆ OUT

const int cvui::OUT = 5

Referenced by main().

◆ OVER

const int cvui::OVER = 4

Referenced by main().

◆ RIGHT_BUTTON

const int cvui::RIGHT_BUTTON = 2

Referenced by main().

◆ ROW

const int cvui::ROW = 0

◆ TRACKBAR_DISCRETE

const unsigned int cvui::TRACKBAR_DISCRETE = 4

Referenced by main().

◆ TRACKBAR_HIDE_LABELS

const unsigned int cvui::TRACKBAR_HIDE_LABELS = 32

◆ TRACKBAR_HIDE_MIN_MAX_LABELS

const unsigned int cvui::TRACKBAR_HIDE_MIN_MAX_LABELS = 8

◆ TRACKBAR_HIDE_SEGMENT_LABELS

const unsigned int cvui::TRACKBAR_HIDE_SEGMENT_LABELS = 1

Referenced by main().

◆ TRACKBAR_HIDE_STEP_SCALE

const unsigned int cvui::TRACKBAR_HIDE_STEP_SCALE = 2

◆ TRACKBAR_HIDE_VALUE_LABEL

const unsigned int cvui::TRACKBAR_HIDE_VALUE_LABEL = 16

◆ UP

const int cvui::UP = 6

Referenced by main().

cvui::DOWN
const int DOWN
Definition: cvui.h:1149
cvui::text
void text(cv::Mat &theWhere, int theX, int theY, const cv::String &theText, double theFontScale=0.4, unsigned int theColor=0xCECECE)
Display a piece of text.
cvui::endColumn
void endColumn()
End a column.
cvui::endRow
void endRow()
Ends a row.
cvui::mouse
cv::Point mouse(const cv::String &theWindowName="")
Return the last position of the mouse.
cvui::printf
void printf(cv::Mat &theWhere, int theX, int theY, double theFontScale, unsigned int theColor, const char *theFmt,...)
Display a piece of text that can be formated using stdio's printf() style.
cvui::beginColumn
void beginColumn(cv::Mat &theWhere, int theX, int theY, int theWidth=-1, int theHeight=-1, int thePadding=0)
Start a new column.
cvui::trackbar
bool trackbar(cv::Mat &theWhere, int theX, int theY, int theWidth, T *theValue, T theMin, T theMax, int theSegments=1, const char *theLabelFormat="%.1Lf", unsigned int theOptions=0, T theDiscreteStep=1)
Display a trackbar for numeric values that the user can increase/decrease by clicking and/or dragging...
cvui::beginRow
void beginRow(cv::Mat &theWhere, int theX, int theY, int theWidth=-1, int theHeight=-1, int thePadding=0)
Start a new row.
cvui::context
void context(const cv::String &theWindowName)
Inform cvui that all subsequent component calls belong to a window in particular.
cvui::imshow
void imshow(const cv::String &theWindowName, cv::InputArray theFrame)
Display an image in the specified window and update the internal structures of cvui.
cvui::button
bool button(cv::Mat &theWhere, int theX, int theY, const cv::String &theLabel)
Display a button.
cvui::update
void update(const cv::String &theWindowName="")
Update the library internal things.