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

Child-classe, applies a mask to the input matrix. More...

#include <Mask.h>

Inheritance diagram for Mask:

Public Member Functions

 Mask (const cv::String name)
 Constructor. More...
 
 Mask (const cv::String name, HSV_MASK_VALUES hsv)
 Constructor. More...
 
void setAction (void *data)
 sets the output of the action More...
 
void showWindow ()
 shows the action to the user More...
 
- Public Member Functions inherited from PipeLineAction
 PipeLineAction ()
 Default constructor.
 
 PipeLineAction (const cv::String name)
 Constructor. More...
 
virtual void * getAction ()
 gets the output of the action More...
 
void hideWindow ()
 hides the action to the user More...
 
cv::String getName ()
 gets the pipeline action name More...
 

Static Private Member Functions

static void onLowHTreshTrackbar (int, void *data)
 Handles the change trackbar event for the low hue trackbar. More...
 
static void onHighHTreshTrackbar (int, void *data)
 Handles the change trackbar event for the high hue trackbar. More...
 
static void onLowSTreshTrackbar (int, void *data)
 Handles the change trackbar event for the low saturation trackbar. More...
 
static void onHighSTreshTrackbar (int, void *data)
 Handles the change trackbar event for the high saturation trackbar. More...
 
static void onLowVTreshTrackbar (int, void *data)
 Handles the change trackbar event for the low value trackbar. More...
 
static void onHighVTreshTrackbar (int, void *data)
 Handles the change trackbar event for the high value trackbar. More...
 

Private Attributes

const int maxValueH = 180
 maximum value of the hue trackbar
 
const int maxValue = 255
 maximum value of the saturation and value trackbars
 
const int maxValuePixel = 10
 maximum value of the associated trackbar
 
int lowH
 current value of the low hue trackbar
 
int lowS
 current value of the low saturation trackbar
 
int lowV
 current value of the low value trackbar
 
int highH
 current value of the high hue trackbar
 
int highS
 current value of the high saturation trackbar
 
int highV
 current value of the high value trackbar
 
int pixelSize
 current value of the erode and dilate size, based on the pixelsize trackbar position
 

Additional Inherited Members

- Protected Attributes inherited from PipeLineAction
cv::Mat img
 Matrix which holds the image of the action.
 
bool show
 Show action flag.
 
cv::String name
 (screen)name of the pipeline action
 

Detailed Description

Child-classe, applies a mask to the input matrix.

Constructor & Destructor Documentation

◆ Mask() [1/2]

Mask::Mask ( const cv::String  name)

Constructor.

Parameters
name(screen)name of mask action
15 {
16  lowH = 0, lowS = 0, lowV = 0;
18 
19  pixelSize = 2;
20 }
int lowH
current value of the low hue trackbar
Definition: Mask.h:35
int pixelSize
current value of the erode and dilate size, based on the pixelsize trackbar position
Definition: Mask.h:43
const int maxValue
maximum value of the saturation and value trackbars
Definition: Mask.h:32
int highS
current value of the high saturation trackbar
Definition: Mask.h:40
int highH
current value of the high hue trackbar
Definition: Mask.h:39
int lowV
current value of the low value trackbar
Definition: Mask.h:37
int lowS
current value of the low saturation trackbar
Definition: Mask.h:36
int highV
current value of the high value trackbar
Definition: Mask.h:41
const int maxValueH
maximum value of the hue trackbar
Definition: Mask.h:31
cv::String name
(screen)name of the pipeline action
Definition: PipeLineAction.h:27
PipeLineAction()
Default constructor.
Definition: PipeLineAction.cpp:11

◆ Mask() [2/2]

Mask::Mask ( const cv::String  name,
HSV_MASK_VALUES  hsv 
)

Constructor.

Parameters
name(screen)name of mask action
hsvstruct containing the HGV mask values
23 {
24  this->lowH = hsvValues.lowH;
25  this->lowS = hsvValues.lowS;
26  this->lowV = hsvValues.lowV;
27  this->highH = hsvValues.highH;
28  this->highS = hsvValues.highS;
29  this->highV = hsvValues.highV;
30 
31  pixelSize = 2;
32 }

Member Function Documentation

◆ setAction()

void Mask::setAction ( void *  data)
virtual

sets the output of the action

in this case: applying a mask to the input matrix. The mask is based on the trackbar values.

Parameters
datapointer to the input data, should be a OpenCV matrix

Implements PipeLineAction.

35 {
36  Mat* d = static_cast<Mat*>(data);
37  inRange(*d,
38  Scalar(lowH, lowS, lowV),
39  Scalar(highH, highS, highV),
40  img);
41  erode(img, img, pixelSize);
42  dilate(img, img, pixelSize);
43 }
cv::Mat img
Matrix which holds the image of the action.
Definition: PipeLineAction.h:25

◆ showWindow()

void Mask::showWindow ( )
virtual

shows the action to the user

uses cv::imshow(). The name of the window is the name of the pipeline action. Trackbars are added to set max and min values of

  • Hue
  • Saturation
  • Value

Implements PipeLineAction.

46 {
47  if (!show) {
48  namedWindow(name);
49  createTrackbar("Low H", name, &lowH, maxValueH, onLowHTreshTrackbar, this);
50  createTrackbar("High H", name, &highH, maxValueH, onHighHTreshTrackbar, this);
51  createTrackbar("Low S", name, &lowS, maxValue, onLowSTreshTrackbar, this);
52  createTrackbar("High S", name, &highS, maxValue, onHighSTreshTrackbar, this);
53  createTrackbar("Low V", name, &lowV, maxValue, onLowVTreshTrackbar, this);
54  createTrackbar("High V", name, &highV, maxValue, onHighVTreshTrackbar, this);
55  createTrackbar("Pixel size", name, &pixelSize, maxValuePixel, onHighVTreshTrackbar, this);
56  show = true;
57  }
58  imshow(name, img);
59 }
static void onHighHTreshTrackbar(int, void *data)
Handles the change trackbar event for the high hue trackbar.
Definition: Mask.cpp:68
const int maxValuePixel
maximum value of the associated trackbar
Definition: Mask.h:33
static void onHighVTreshTrackbar(int, void *data)
Handles the change trackbar event for the high value trackbar.
Definition: Mask.cpp:96
static void onLowVTreshTrackbar(int, void *data)
Handles the change trackbar event for the low value trackbar.
Definition: Mask.cpp:89
static void onLowHTreshTrackbar(int, void *data)
Handles the change trackbar event for the low hue trackbar.
Definition: Mask.cpp:61
static void onHighSTreshTrackbar(int, void *data)
Handles the change trackbar event for the high saturation trackbar.
Definition: Mask.cpp:82
static void onLowSTreshTrackbar(int, void *data)
Handles the change trackbar event for the low saturation trackbar.
Definition: Mask.cpp:75
bool show
Show action flag.
Definition: PipeLineAction.h:26
Here is the call graph for this function:

◆ onLowHTreshTrackbar()

void Mask::onLowHTreshTrackbar ( int  ,
void *  data 
)
staticprivate

Handles the change trackbar event for the low hue trackbar.

sets the trackbar position bepending on the min of the high and low value

Parameters
datapointer to the mask object associated with the trackbar
62 {
63  Mask* m = static_cast<Mask*>(data);
64  m->lowH = min(m->highH - 1, m->lowH);
65  setTrackbarPos("Low H", m->name, m->lowH);
66 }
Child-classe, applies a mask to the input matrix.
Definition: Mask.h:28
Here is the caller graph for this function:

◆ onHighHTreshTrackbar()

void Mask::onHighHTreshTrackbar ( int  ,
void *  data 
)
staticprivate

Handles the change trackbar event for the high hue trackbar.

sets the trackbar position bepending on the min of the high and low value

Parameters
datapointer to the mask object associated with the trackbar
69 {
70  Mask* m = static_cast<Mask*>(data);
71  m->highH = max(m->highH, m->lowH + 1);
72  setTrackbarPos("High H", m->name, m->highH);
73 }
Here is the caller graph for this function:

◆ onLowSTreshTrackbar()

void Mask::onLowSTreshTrackbar ( int  ,
void *  data 
)
staticprivate

Handles the change trackbar event for the low saturation trackbar.

sets the trackbar position bepending on the min of the high and low value

Parameters
datapointer to the mask object associated with the trackbar
76 {
77  Mask* m = static_cast<Mask*>(data);
78  m->lowS = min(m->highS - 1, m->lowS);
79  setTrackbarPos("Low S", m->name, m->lowS);
80 }
Here is the caller graph for this function:

◆ onHighSTreshTrackbar()

void Mask::onHighSTreshTrackbar ( int  ,
void *  data 
)
staticprivate

Handles the change trackbar event for the high saturation trackbar.

sets the trackbar position bepending on the min of the high and low value

Parameters
datapointer to the mask object associated with the trackbar
83 {
84  Mask* m = static_cast<Mask*>(data);
85  m->highS = max(m->highS, m->lowS + 1);
86  setTrackbarPos("High S", m->name, m->highS);
87 }
Here is the caller graph for this function:

◆ onLowVTreshTrackbar()

void Mask::onLowVTreshTrackbar ( int  ,
void *  data 
)
staticprivate

Handles the change trackbar event for the low value trackbar.

sets the trackbar position bepending on the min of the high and low value

Parameters
datapointer to the mask object associated with the trackbar
90 {
91  Mask* m = static_cast<Mask*>(data);
92  m->lowV = min(m->highV - 1, m->lowV);
93  setTrackbarPos("Low V", m->name, m->lowV);
94 }
Here is the caller graph for this function:

◆ onHighVTreshTrackbar()

void Mask::onHighVTreshTrackbar ( int  ,
void *  data 
)
staticprivate

Handles the change trackbar event for the high value trackbar.

sets the trackbar position bepending on the min of the high and low value

Parameters
datapointer to the mask object associated with the trackbar
97 {
98  Mask* m = static_cast<Mask*>(data);
99  m->highV = max(m->highV, m->lowV + 1);
100  setTrackbarPos("High V", m->name, m->highV);
101 }
Here is the caller graph for this function: