OSVR-Core
LED.h
Go to the documentation of this file.
1 
11 // Copyright 2015 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 #ifndef INCLUDED_LED_h_GUID_C53E1134_AD6B_46B0_4808_19C7EAA7D0EC
26 #define INCLUDED_LED_h_GUID_C53E1134_AD6B_46B0_4808_19C7EAA7D0EC
27 
28 // Internal Includes
29 #include "LedIdentifier.h"
30 #include "LedMeasurement.h"
31 
32 // Library/third-party includes
33 #include <opencv2/core/core.hpp>
34 
35 // Standard includes
36 #include <vector>
37 
38 namespace osvr {
39 namespace vbtracker {
40 
41  static const bool USING_INVERTED_LED_POSITION = true;
42 
47  class Led {
48  public:
49  static const int SENTINEL_NO_IDENTIFIER_OBJECT_OR_INSUFFICIENT_DATA =
50  -1;
51  static const int SENTINEL_INSUFFICIENT_EXTREMA_DIFFERENCE = -2;
52  static const int
53  SENTINEL_NO_PATTERN_RECOGNIZED_DESPITE_SUFFICIENT_DATA = -3;
54  static const int SENTINEL_NO_IDENTIFIER_OBJECT = -4;
55  static const int SENTINEL_MARKED_MISIDENTIFIED = -5;
56 
62  Led(LedIdentifier *identifier, LedMeasurement const &meas);
64 
65  static const uint8_t MAX_NOVELTY = 4;
77  void addMeasurement(LedMeasurement const &meas, bool blobsKeepId);
78 
79  LedMeasurement const &getMeasurement() const {
80  return m_latestMeasurement;
81  }
82 
89  ZeroBasedBeaconId getID() const { return m_id; }
90 
94 
96  bool identified() const { return beaconIdentified(getID()); }
97 
104  uint8_t novelty() const { return m_novelty; }
105 
107  cv::Point2f getLocation() const { return m_latestMeasurement.loc; }
108 
111  cv::Point2f getInverseLocation() const {
112  return cv::Point2f(m_latestMeasurement.imageSize.width -
113  m_latestMeasurement.loc.x,
114  m_latestMeasurement.imageSize.height -
115  m_latestMeasurement.loc.y);
116  }
117 
123  cv::Point2f getLocationForTracking() const {
124  return USING_INVERTED_LED_POSITION ? getInverseLocation()
125  : getLocation();
126  }
127 
133  KeyPointIterator nearest(KeyPointList &keypoints,
134  double threshold) const;
135 
137  LedMeasurementVecIterator nearest(LedMeasurementVec &meas,
138  double threshold) const;
139 
143  bool isBright() const { return m_lastBright; }
144 
146  bool wasUsedLastFrame() const { return m_wasUsedLastFrame; }
147 
149  void markAsUsed() { m_wasUsedLastFrame = true; }
150 
151  void resetUsed() { m_wasUsedLastFrame = false; }
152 
155  void markMisidentified();
156 
157  private:
159  LedMeasurement m_latestMeasurement;
160 
162  BrightnessList m_brightnessHistory;
163 
166  ZeroBasedBeaconId m_id =
167  ZeroBasedBeaconId(SENTINEL_NO_IDENTIFIER_OBJECT);
168 
170  LedIdentifier *m_identifier = nullptr;
171 
173  bool m_lastBright = false;
174 
175  bool m_newlyRecognized = false;
176  uint8_t m_novelty;
177 
178  bool m_wasUsedLastFrame = false;
179  };
180 
181 } // End namespace vbtracker
182 } // End namespace osvr
183 
184 #endif // INCLUDED_LED_h_GUID_C53E1134_AD6B_46B0_4808_19C7EAA7D0EC
Helper class to keep track of the state of a blob over time.
Definition: LED.h:47
void markAsUsed()
Call from inside the tracking algorithm to mark that it was used.
Definition: LED.h:149
cv::Point2f getInverseLocation() const
Gets the most-recently-added position, in a xy-origin-at-bottom-left coordinate system.
Definition: LED.h:111
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
Led(LedIdentifier *identifier, LedMeasurement const &meas)
Definition: LED.cpp:30
uint8_t novelty() const
Returns a value (decreasing per frame from some maximum down to a minimum of zero) indicating how new...
Definition: LED.h:104
void addMeasurement(LedMeasurement const &meas, bool blobsKeepId)
Add a new measurement for this LED, which must be for a frame that is just following the previous mea...
Definition: LED.cpp:37
ZeroBasedBeaconId getID() const
Tells which LED I am.
Definition: LED.h:89
void markMisidentified()
Called from within pose estimation or elsewhere with model-based knowledge that can refute the identi...
Definition: LED.cpp:76
bool isBright() const
Returns the most-recent boolean "bright" state according to the LED identifier.
Definition: LED.h:143
cv::Point2f loc
Location in image space - should be undistorted when passed to the Led class.
Definition: LedMeasurement.h:77
cv::Point2f getLocation() const
Reports the most-recently-added position.
Definition: LED.h:107
bool wasUsedLastFrame() const
Used for a status display in debug windows.
Definition: LED.h:146
OneBasedBeaconId getOneBasedID() const
Gets either the raw negative sentinel ID or a 1-based ID (for display purposes)
Definition: LED.h:93
bool identified() const
Do we have a positive identification as a known LED?
Definition: LED.h:96
OneBasedBeaconId makeOneBased(ZeroBasedBeaconId id)
Overloaded conversion function to turn any beacon ID into one-based, respecting the convention that n...
Definition: BeaconIdTypes.h:79
cv::Size imageSize
Size of the image the measurement came from.
Definition: LedMeasurement.h:80
Definition: LedMeasurement.h:41
bool beaconIdentified(ZeroBasedBeaconId id)
Does the given beacon ID indicate that it&#39;s identified?
Definition: BeaconIdTypes.h:118
cv::Point2f getLocationForTracking() const
Gets the most-recently-added position in the coordinate system to be used for tracking.
Definition: LED.h:123
Header file for class that identifies LEDs based on blink codes.
KeyPointIterator nearest(KeyPointList &keypoints, double threshold) const
Find the nearest KeyPoint from a container of points to me, if there is one within the specified thre...
Definition: LED.cpp:74
Helper class to identify an LED based on its pattern of brightness over time.
Definition: LedIdentifier.h:53