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

Displays the output of the serial communication. Member of GUI classes Graphic group. More...

#include <Console.h>

Classes

struct  STYLE
 Console style information. More...
 

Public Member Functions

 Console ()
 Default constructor.
 
 Console (cv::Size size)
 Constructor. More...
 
void setSize (cv::Size size)
 sets the size of the Matrix More...
 
void addMessage (string message)
 adds a message to de message deque More...
 
cv::Mat draw ()
 Draws the serial communication messages to the image. More...
 

Private Member Functions

cv::Scalar messageColor (std::string str)
 returns color based on the message text More...
 

Private Attributes

const cv::Scalar backGroundColor = cv::Scalar(0, 0, 0)
 Color of the console background.
 
cv::Mat img
 Image matrix of the Console.
 
cv::Size size
 Size of the image matrix.
 
deque< string > messages
 all messages from console
 
struct Console::STYLE style
 Console style information.
 

Detailed Description

Displays the output of the serial communication. Member of GUI classes Graphic group.

Constructor & Destructor Documentation

◆ Console()

Console::Console ( cv::Size  size)

Constructor.

Creates a empty image, with hight and width set by size and fills it with a color.

Warning
, not working at the moment...
Parameters
sizeHight and width of the image matrix
35 {
36  this->size = size;
37  img = Mat::zeros(size, CV_8UC3);
38  rectangle(img, Point(0, 0), size, backGroundColor, -1);
39 }
cv::Mat img
Image matrix of the Console.
Definition: Console.h:27
cv::Size size
Size of the image matrix.
Definition: Console.h:28
const cv::Scalar backGroundColor
Color of the console background.
Definition: Console.h:26

Member Function Documentation

◆ messageColor()

Scalar Console::messageColor ( std::string  str)
private

returns color based on the message text

  • "OK:" = green
  • "ERROR:" = red
  • unknow = yellow
    Parameters
    strstring containing the message
    Returns
    Scalar: BGR color
14 {
15 
16  if (0 == strncmp("ERROR:", str.c_str(), 6)) {
17  return style.fontColorError;
18  }
19  else if (0 == strncmp("OK:", str.c_str(), 3)) {
20  return style.fontColorOK;
21  }
22  else {
23  return style.fontColorWarning;
24  }
25 }
struct Console::STYLE style
Console style information.
cv::Scalar fontColorError
Color of ERROR message (Red)
Definition: Console.h:37
cv::Scalar fontColorOK
Color of OK message (Green)
Definition: Console.h:36
cv::Scalar fontColorWarning
Color of Warning/unknow message (Yellow)
Definition: Console.h:38

◆ setSize()

void Console::setSize ( cv::Size  size)

sets the size of the Matrix

functionality is equal to Console(CV::Size size);

Parameters
sizeHight and width of the image matrix
42 {
43  this->size = size;
44  img = Mat::zeros(size, CV_8UC3);
45  rectangle(img, Point(0, 0), size, backGroundColor, -1);
46 }

◆ addMessage()

void Console::addMessage ( string  message)

adds a message to de message deque

Parameters
messagestring containing the message
49 {
50  if (messages.size() >= 10)
51  messages.pop_front();
52  messages.push_back(message);
53 }
deque< string > messages
all messages from console
Definition: Console.h:29

◆ draw()

cv::Mat Console::draw ( )

Draws the serial communication messages to the image.

Loops over al messages and draws them with a height offset of 5 pixels between each message.

Returns
the image matrix
56 {
57  if (messages.size() > 0) {
58  //Draw background rectangle
59  rectangle(img, Point(0, 0), size, backGroundColor, -1);
60 
61  //Get text Size
62  int baseLine = 0;
63  Size textSize = getTextSize(messages[0], style.fontFace, style.fontScale, 1, &baseLine);
64 
65  //Draw all messages from de deque, offset between strings = 5 pixels
66  float y = 2; //Initial y offset
67  deque<string>::iterator it;
68  for (it = messages.begin(); it != messages.end(); it++)
69  {
70  Scalar fontColor = messageColor(*it);
71  Point textOrg(2, (y + textSize.height));
72  putText(img, (*it), textOrg, style.fontFace, style.fontScale, fontColor, 1, 8);
73  y += (textSize.height) + 5;
74  }
75  }
76  return img;
77 }
cv::Scalar messageColor(std::string str)
returns color based on the message text
Definition: Console.cpp:13
float fontScale
Font size.
Definition: Console.h:35
int fontFace
Font type.
Definition: Console.h:34