SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
CVTrackedArucoCube.h
Go to the documentation of this file.
1 /**
2  * \file CVTrackedArucoCube.h
3  * \date September 2021
4  * \authors Marino von Wattenwyl
5  * \copyright http://opensource.org/licenses/GPL-3.0
6  * \remarks Please use clangformat to format the code. See more code style on
7  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
8 */
9 
10 #ifndef SLPROJECT_CVTRACKEDARUCOCUBE_H
11 #define SLPROJECT_CVTRACKEDARUCOCUBE_H
12 
13 #include <CVTypedefs.h>
14 #include <CVTrackedAruco.h>
15 
16 // TODO: Replace with OpenCV classes, SL not allowed in OpenCV module
17 #include <SLQuat4.h>
18 
19 //-----------------------------------------------------------------------------
21 {
22 public:
23  AveragedQuat4f(int numValues, SLQuat4f initValue)
24  {
25  init(numValues, initValue);
26  }
27 
28  //! Initializes the average value array to a given value
29  void init(int numValues, SLQuat4f initValue)
30  {
31  assert(numValues > 0 && "Num. of values must be greater than zero");
32  _values.clear();
33  _values.resize(numValues, initValue);
34  _oneOverNumValues = 1.0f / (float)_values.size();
35  _average = initValue;
37  }
38 
39  //! Sets the current value in the value array and builds the average
40  void set(SLQuat4f value)
41  {
42  assert(_values.size() > 0 && "_value vector not initialized");
43 
44  // Short cut for no averaging
45  if (_values.size() == 1)
46  _average = value;
47  else
48  {
49  if (_currentValueIndex == _values.size())
51 
52  // Correct the sum continuously
53  _values[_currentValueIndex] = value;
54 
55  _average.set(0.0f, 0.0f, 0.0f, 0.0f);
56  for (int i = 0; i < _values.size(); i++)
57  {
58  SLQuat4f current = _values[i];
59  float weight = _oneOverNumValues;
60 
61  if (i > 0 && current.dot(_values[0]) < -0.001)
62  weight = -weight;
63 
64  _average.set(_average.x() + current.x() * weight,
65  _average.y() + current.y() * weight,
66  _average.z() + current.z() * weight,
67  _average.w() + current.w() * weight);
68  }
69 
71 
73  }
74  }
75 
76  SLQuat4f average() { return _average; }
77  size_t size() { return _values.size(); }
78 
79 private:
80  float _oneOverNumValues{}; //!< multiplier instead of divider
81  vector<SLQuat4f> _values; //!< value array
82  int _currentValueIndex{}; //!< current value index within _values
83  SLQuat4f _average; //!< average value
84 };
85 //-----------------------------------------------------------------------------
86 //! OpenCV ArUco cube marker tracker class derived from CVTrackedAruco
87 /*! Tracks a cube of ArUco markers and averages their values. The origin
88  * of the cube is in the center.
89  * The markers must be placed in the following manner:
90  * ID 0: front
91  * ID 1: right
92  * ID 2: back
93  * ID 3: left
94  * ID 4: top
95  * ID 5: bottom
96  */
98 {
99 public:
100  CVTrackedArucoCube(string calibIniPath, float edgeLength);
101 
102  bool track(CVMat imageGray,
103  CVMat imageBgr,
104  CVCalibration* calib);
105 
106 private:
107  float _edgeLength;
108 
111 
112 public:
113  CVRect _roi = CVRect(0, 0, 0, 0);
114 };
115 //-----------------------------------------------------------------------------
116 #endif // SLPROJECT_CVTRACKEDARUCOCUBE_H
cv::Rect CVRect
Definition: CVTypedefs.h:39
cv::Mat CVMat
Definition: CVTypedefs.h:38
void init(int numValues, SLQuat4f initValue)
Initializes the average value array to a given value.
vector< SLQuat4f > _values
value array
AveragedQuat4f(int numValues, SLQuat4f initValue)
void set(SLQuat4f value)
Sets the current value in the value array and builds the average.
int _currentValueIndex
current value index within _values
float _oneOverNumValues
multiplier instead of divider
SLQuat4f _average
average value
Live video camera calibration class with OpenCV an OpenCV calibration.
Definition: CVCalibration.h:71
OpenCV ArUco cube marker tracker class derived from CVTrackedAruco.
Averaged< CVVec3f > _averagePosition
AveragedQuat4f _averageRotation
CVTrackedArucoCube(string calibIniPath, float edgeLength)
bool track(CVMat imageGray, CVMat imageBgr, CVCalibration *calib)
Tracks the all Aruco markers in the given image for the first sceneview.
OpenCV ArUco marker tracker class derived from CVTracked.
T w() const
Definition: SLQuat4.h:39
void set(T x, T y, T z, T w)
Definition: SLQuat4.h:140
T z() const
Definition: SLQuat4.h:38
T dot(const SLQuat4< T > &q) const
Definition: SLQuat4.h:536
T y() const
Definition: SLQuat4.h:37
T x() const
Definition: SLQuat4.h:36
T normalize()
Definition: SLQuat4.h:575