OSVR-Core
LedMeasurement.h
Go to the documentation of this file.
1 
11 // Copyright 2016 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_LedMeasurement_h_GUID_FB847F67_347B_4C8E_AC9B_33179ED6B0E6
26 #define INCLUDED_LedMeasurement_h_GUID_FB847F67_347B_4C8E_AC9B_33179ED6B0E6
27 
28 // Internal Includes
29 #include "BasicTypes.h"
30 
31 // Library/third-party includes
32 #include <opencv2/core/core.hpp>
33 #include <opencv2/features2d/features2d.hpp>
34 
35 // Standard includes
36 #include <cassert>
37 #include <vector>
38 
39 namespace osvr {
40 namespace vbtracker {
41  struct LedMeasurement {
42  private:
43  static float estimateArea(float diameter) {
44  return static_cast<float>((diameter / 2) * (diameter / 2) * CV_PI);
45  }
46 
47  public:
48  LedMeasurement() = default;
52  LedMeasurement(cv::Point2f location, float diam, cv::Size imgSize,
53  float beaconArea = -1)
54  : loc(location), imageSize(imgSize), brightness(diam),
55  diameter(diam),
56  area(beaconArea <= 0 ? estimateArea(diameter) : beaconArea) {}
57 
61  LedMeasurement(cv::KeyPoint const &kp, cv::Size imgSize,
62  float beaconArea = -1)
63  : LedMeasurement(kp.pt, kp.size, imgSize, beaconArea) {
65  }
66 
69  LedMeasurement(float x, float y, float diam, cv::Size imgSize,
70  float beaconArea = -1)
71  : LedMeasurement(cv::Point2f(x, y), diam, imgSize, beaconArea) {
73  }
74 
77  cv::Point2f loc;
78 
80  cv::Size imageSize;
81 
83  Brightness brightness;
84 
86  float diameter = 0.f;
87 
89  float area = 1.f;
90 
92  float circularity = 0.f;
93 
96  bool knowBoundingBox() const { return knowBoundingBox_; }
97 
100  cv::Size2f boundingBoxSize() const {
101  assert(knowBoundingBox() && "call to boundingBoxSize() invalid if "
102  "knowBoundingBox() is false");
103  return boundingBox_;
104  }
105 
107  void setBoundingBox(cv::Size2f size) {
108  knowBoundingBox_ = true;
109  boundingBox_ = size;
110  }
111 
113  void setBoundingBox(cv::Rect const &box) {
114  knowBoundingBox_ = true;
115  boundingBox_ = box.size();
116  }
117 
118  bool operator==(LedMeasurement const &other) const {
119  return loc == other.loc && brightness == other.brightness &&
120  circularity == other.circularity &&
121  knowBoundingBox_ == other.knowBoundingBox_ &&
122  (knowBoundingBox_ ? boundingBox_ == other.boundingBox_
123  : true) &&
124  // less likely to differ
125  imageSize == other.imageSize &&
126  // technically equivalent or derived from other properties
127  diameter == other.diameter && area == other.area;
128  }
129 
130  private:
133  bool knowBoundingBox_ = false;
135  cv::Size2f boundingBox_;
136  };
137 
138  typedef std::vector<LedMeasurement> LedMeasurementVec;
139  typedef LedMeasurementVec::iterator LedMeasurementVecIterator;
140 
141 } // namespace vbtracker
142 } // namespace osvr
143 #endif // INCLUDED_LedMeasurement_h_GUID_FB847F67_347B_4C8E_AC9B_33179ED6B0E6
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
float area
Area in pixels.
Definition: LedMeasurement.h:89
cv::Size2f boundingBoxSize() const
Dimensions of the upright bounding box.
Definition: LedMeasurement.h:100
void setBoundingBox(cv::Size2f size)
Set the upright bounding box (from a size)
Definition: LedMeasurement.h:107
LedMeasurement(cv::Point2f location, float diam, cv::Size imgSize, float beaconArea=-1)
Constructor for a measurement.
Definition: LedMeasurement.h:52
bool knowBoundingBox() const
Do we know an upright bounding box? (that is, is the next member valid?)
Definition: LedMeasurement.h:96
detail::size< coerce_list< Ts... >> size
Get the size of a list (number of elements.)
Definition: Size.h:56
cv::Point2f loc
Location in image space - should be undistorted when passed to the Led class.
Definition: LedMeasurement.h:77
Header.
cv::Size imageSize
Size of the image the measurement came from.
Definition: LedMeasurement.h:80
float diameter
Blob diameter in pixels.
Definition: LedMeasurement.h:86
Definition: LedMeasurement.h:41
LedMeasurement(cv::KeyPoint const &kp, cv::Size imgSize, float beaconArea=-1)
Constructor for a measurement from a KeyPoint and image size.
Definition: LedMeasurement.h:61
float circularity
Blob circularity (as defined by OpenCV) - in [0,1].
Definition: LedMeasurement.h:92
void setBoundingBox(cv::Rect const &box)
Set the upright bounding box (from a Rect)
Definition: LedMeasurement.h:113
LedMeasurement(float x, float y, float diam, cv::Size imgSize, float beaconArea=-1)
Constructor primarily used by replay for calibration/optimization purposes.
Definition: LedMeasurement.h:69
Brightness brightness
"Brightness" - currently actually diameter.
Definition: LedMeasurement.h:83