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

Child-classe, implements OpenCV's center of mass finding. More...

#include <Moment.h>

Inheritance diagram for Moment:

Public Member Functions

 Moment (const cv::String name)
 Constructor. More...
 
void setAction (void *data)
 sets the output of the action More...
 
void * getAction ()
 gets the output of the action More...
 
cv::Point * getCenterOfMass ()
 gets 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...
 
void hideWindow ()
 hides the action to the user More...
 
cv::String getName ()
 gets the pipeline action name More...
 

Private Attributes

cv::Moments m
 struct containing spatial moment
 
cv::Point center
 vector containing all contour points
 
int areaMax
 highest value of the trackbar
 
int area
 current value of the trackbar, used as area filter
 

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, implements OpenCV's center of mass finding.

Constructor & Destructor Documentation

◆ Moment()

Moment::Moment ( const cv::String  name)

Constructor.

Parameters
name(screen)name of mask action
14 {
15  Moments m = Moments();
16  Point center = Point(0, 0);
17  area = 50;
18  areaMax = 1000;
19 }
cv::Moments m
struct containing spatial moment
Definition: Moment.h:17
int area
current value of the trackbar, used as area filter
Definition: Moment.h:20
cv::Point center
vector containing all contour points
Definition: Moment.h:18
int areaMax
highest value of the trackbar
Definition: Moment.h:19
cv::String name
(screen)name of the pipeline action
Definition: PipeLineAction.h:27
PipeLineAction()
Default constructor.
Definition: PipeLineAction.cpp:11

Member Function Documentation

◆ setAction()

void Moment::setAction ( void *  data)
virtual

sets the output of the action

in this case: finding the center of mass at the first index of the vector. If the input vector is empty the center is placed out of sight.

Parameters
datapointer to the input data, should be a vector with points

Implements PipeLineAction.

22 {
23  vector<vector<Point>>* d = static_cast<vector<vector<Point>>*>(data);
24  if (!d->empty()) {
25  m = moments((*d)[(*d).size() - 1], false);
26  center = Point(m.m10 / m.m00, m.m01 / m.m00);
27  }
28  else {
29  center = Point(-10, -10);
30  }
31 }

◆ getAction()

void * Moment::getAction ( )
virtual

gets the output of the action

Returns
Point containing X and Y coordinats of the biggest contours center of mass

Reimplemented from PipeLineAction.

34 {
35  return &center;
36 }

◆ getCenterOfMass()

Point * Moment::getCenterOfMass ( )

gets the output of the action

Returns
Point containing X and Y coordinats of the biggest contours center of mass
39 {
40  return &center;
41 }
Here is the caller graph for this function:

◆ showWindow()

void Moment::showWindow ( )
virtual

shows the action to the user

uses cv::imshow(). The name of the window is the name of the pipeline action. Trackbar is added to set the size of the approximation accuracy

Implements PipeLineAction.

44 {
45  show = false;
46 }
bool show
Show action flag.
Definition: PipeLineAction.h:26