Webcam Tracker  V1.0
Using openCV and an Arduino Uno
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members

Contains the graphic user interface main class. Member of GUI classes Graphic group. More...

#include <GUI.h>

Public Member Functions

 GUI ()
 Default constructor.
 
 GUI (vector< PipeLineAction * > actions)
 Constructor. More...
 
void showOutput (cv::Mat &src, cv::Point *trackingPoint)
 shows the output Matrix to the user More...
 
void showWindows (vector< PipeLineAction * > actions)
 shows pipeline action windows depending on the state of the corresponding menu button More...
 
void addMessage (string message)
 adds a message to the GUI console More...
 
bool trackingActive ()
 gets the tracking state More...
 

Private Member Functions

void createButtonStates ()
 Constructs the button state vector. More...
 
void checkButtonStates ()
 Checks the state of all menu buttons. More...
 

Static Private Member Functions

static void onMouse (int event, int x, int y, int, void *userdata)
 mouse call back function More...
 

Private Attributes

const cv::String sourceWindow = "Tracking application"
 Name of the GUI window.
 
Menu menu
 Object holding the menu class.
 
Console console
 Object holding the console class.
 
vector< bool > buttonStates
 All button states, from the menu in one vector.
 
bool tracking
 Tracking active flag.
 

Detailed Description

Contains the graphic user interface main class. Member of GUI classes Graphic group.

Constructor & Destructor Documentation

◆ GUI()

GUI::GUI ( vector< PipeLineAction * >  actions)

Constructor.

Creates a named window, a menu and a console. The menu buttons are named after the pipeline actions. Lines up the buttons length wise and creates a mouse event listener

Parameters
actionsvector containing pointers to all pipeline actions
46 {
47  cv::namedWindow(sourceWindow, cv::WINDOW_AUTOSIZE);
48 
49  menu = Menu(Size(800, 40));
50  console.setSize(Size(800, 180));
51 
52  //Create buttons
53  cv::Point startPoint(5, 5);
54  vector<PipeLineAction*>::iterator it;
55  for (it = actions.begin(); it != actions.end(); it++)
56  {
57  menu.addButton(startPoint, 30, (*it)->getName());
58  }
59 
60  menu.addButton(startPoint, 30, "Start Tracking");
61 
62  //shift start points of buttons to end of prev button
63  vector<Button>* buttons = menu.getButtons();
64  vector<Button>::iterator bt;
65  for (bt = buttons->begin(); bt != buttons->end(); bt++)
66  {
67  bt->setStartPoint(startPoint);
68  startPoint.x += bt->getWidth() + 5;
69  }
70 
71 
72  cv::setMouseCallback(sourceWindow, onMouse, &menu);
74 }
void setSize(cv::Size size)
sets the size of the Matrix
Definition: Console.cpp:41
void createButtonStates()
Constructs the button state vector.
Definition: GUI.cpp:13
const cv::String sourceWindow
Name of the GUI window.
Definition: GUI.h:30
static void onMouse(int event, int x, int y, int, void *userdata)
mouse call back function
Definition: GUI.cpp:36
Console console
Object holding the console class.
Definition: GUI.h:33
Menu menu
Object holding the menu class.
Definition: GUI.h:32
Menu like structure with clickable buttons. Member of GUI classes Graphic group.
Definition: Menu.h:23
void addButton(cv::Point startPoint, int height, cv::String text)
Adds a button to the menu.
Definition: Menu.cpp:23
vector< Button > * getButtons()
Gets the buttons.
Definition: Menu.cpp:48
vector< PipeLineAction * > actions
All OpenCV pipeline actions.
Definition: Main.cpp:27

Member Function Documentation

◆ createButtonStates()

void GUI::createButtonStates ( )
private

Constructs the button state vector.

Loops over all buttons in the menu, adds the current state to the vector

14 {
15  vector<Button>::iterator it;
16  vector<Button>* buttons = menu.getButtons();
17  for (it = buttons->begin(); it != buttons->end(); it++)
18  {
19  buttonStates.push_back(it->getClick());
20  }
21 }
vector< bool > buttonStates
All button states, from the menu in one vector.
Definition: GUI.h:34

◆ checkButtonStates()

void GUI::checkButtonStates ( )
private

Checks the state of all menu buttons.

Loops over all buttons in the menu, sets its state in the vector

24 {
25  vector<Button>::iterator it;
26  vector<bool>::iterator ws;
27  vector<Button>* buttons = menu.getButtons();
28  ws = buttonStates.begin();
29  for (it = buttons->begin(); it != buttons->end(); it++)
30  {
31  *ws = it->getClick();
32  ws++;
33  }
34 }

◆ onMouse()

void GUI::onMouse ( int  event,
int  x,
int  y,
int  ,
void *  userdata 
)
staticprivate

mouse call back function

is called when a mouse event occurs, checks if it was a left-mousbutton press and checks if the x,y coordinates are within a button.

Parameters
eventevent type
xX-part of the mouse position
yY-part of the mouse position
userdatapointer to the menu object.
37 {
38  if (event != cv::EVENT_LBUTTONDOWN)
39  return;
40  static_cast<Menu*>(userdata)->checkClicks(x, y);
41 }

◆ showOutput()

void GUI::showOutput ( cv::Mat &  src,
cv::Point *  trackingPoint 
)

shows the output Matrix to the user

Including the tracking point

Parameters
srcsource matrix where the trackingPoint is drawn to
trackingPointcenter of the object to be tracked.
77 {
78  Mat out;
79  circle(src, *trackingPoint, 5, { 0,0,255 }, -1);
80 
81  out.push_back(menu.draw());
82  resize(src, src, Size(800, 460));
83  out.push_back(src);
84  out.push_back(console.draw());
85 
86  imshow(sourceWindow, out);
87 }
cv::Mat draw()
Draws the serial communication messages to the image.
Definition: Console.cpp:55
cv::Mat draw()
Draws all buttons to the image.
Definition: Menu.cpp:27
cv::Mat src
Object holding an OpenCV matrix for the capture source.
Definition: Main.cpp:26
Here is the caller graph for this function:

◆ showWindows()

void GUI::showWindows ( vector< PipeLineAction * >  actions)

shows pipeline action windows depending on the state of the corresponding menu button

Loops over all actions and button states, showing or hiding the action windows. Also sets the tracking flag accourding to its button state

Parameters
actionsvector containing pointers to all pipeline actions
90 {
91  //get current button states
93 
94  //Show or hide windows depending on the buttons state
95  vector<PipeLineAction*>::iterator ac;
96  vector<bool>::iterator ws;
97  ws = buttonStates.begin();
98  for (ac = actions.begin(); ac != actions.end(); ac++)
99  {
100  *ws ? (*ac)->showWindow() : (*ac)->hideWindow();
101  ws++;
102  }
103 
104  *ws ? tracking = true : tracking = false;
105 
106 }
bool tracking
Tracking active flag.
Definition: GUI.h:35
void checkButtonStates()
Checks the state of all menu buttons.
Definition: GUI.cpp:23
Here is the caller graph for this function:

◆ addMessage()

void GUI::addMessage ( string  message)

adds a message to the GUI console

Parameters
messagestring containing the message
109 {
110  console.addMessage(message);
111 }
void addMessage(string message)
adds a message to de message deque
Definition: Console.cpp:48
Here is the caller graph for this function:

◆ trackingActive()

bool GUI::trackingActive ( )

gets the tracking state

Returns
bool: The state of the tracking start button.
114 {
115  return tracking;
116 }
Here is the caller graph for this function: