OSVR-Core
TrackingSystem.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_TrackingSystem_h_GUID_B94B2C23_321F_45B4_5167_CB32D2624B50
26 #define INCLUDED_TrackingSystem_h_GUID_B94B2C23_321F_45B4_5167_CB32D2624B50
27 
28 // Internal Includes
29 #include "ConfigParams.h"
30 #include "ImageProcessing.h"
31 #include "BodyIdTypes.h"
32 #include "CameraParameters.h"
33 
34 // Library/third-party includes
36 #include <osvr/Util/TimeValue.h>
38 #include <opencv2/core/core.hpp>
39 
40 // Standard includes
41 #include <vector>
42 #include <memory>
43 #include <cstddef>
44 #include <unordered_map>
45 
46 namespace osvr {
47 namespace vbtracker {
48  class TrackedBody;
49  class TrackedBodyTarget;
50  using BodyIndices = std::vector<BodyId>;
51 
52  using LedUpdateCount = std::unordered_map<BodyTargetId, std::size_t>;
53 
55  public:
58  TrackingSystem(ConfigParams const &params);
59  ~TrackingSystem();
60  TrackedBody *createTrackedBody();
62 
68  ImageOutputDataPtr performInitialImageProcessing(
69  util::time::TimeValue const &tv, cv::Mat const &frame,
70  cv::Mat const &frameGray, CameraParameters const &camParams);
83  LedUpdateCount const &
84  updateLedsFromVideoData(ImageOutputDataPtr &&imageData);
85 
100  BodyIndices const &
101  updateBodiesFromVideoData(ImageOutputDataPtr &&imageData);
102 
107  BodyIndices const &processFrame(util::time::TimeValue const &tv,
108  cv::Mat const &frame,
109  cv::Mat const &frameGray,
110  CameraParameters const &camParams) {
111  auto imageOutput =
112  performInitialImageProcessing(tv, frame, frameGray, camParams);
113  return updateBodiesFromVideoData(std::move(imageOutput));
114  }
116 
119  std::size_t getNumBodies() const { return m_bodies.size(); }
120  bool isValidBodyId(BodyId i) const {
121  return (!i.empty()) && (i.value() < m_bodies.size());
122  }
123  TrackedBody &getBody(BodyId i) { return *m_bodies.at(i.value()); }
124  TrackedBody const &getBody(BodyId i) const {
125  return *m_bodies.at(i.value());
126  }
127  TrackedBodyTarget *getTarget(BodyTargetId target);
128  TrackedBodyTarget const *getTarget(BodyTargetId target) const;
130 
132  ConfigParams const &getParams() const { return m_params; }
133 
135  void setUseIMU(bool useIMU) { m_params.imu.useOrientation = useIMU; }
136 
137  bool haveCameraPose() const;
138  void setCameraPose(Eigen::Isometry3d const &camPose);
139 
141  Eigen::Isometry3d const &getCameraPose() const;
144  Eigen::Isometry3d const &getRoomToCamera() const;
145 
147 
149  struct Impl;
150 
154  util::time::TimeValue const &tv,
155  Eigen::Quaterniond const &quat);
156 
157  private:
160  void updatePoseEstimates();
161 
164  void calibrationVideoPhaseThree();
165 
166  using BodyPtr = std::unique_ptr<TrackedBody>;
167  ConfigParams m_params;
168 
169  BodyIndices m_updated;
170  std::vector<BodyPtr> m_bodies;
171 
172  std::unique_ptr<Impl> m_impl;
173 
174  friend class TrackingDebugDisplay;
175  };
176 
177 } // namespace vbtracker
178 } // namespace osvr
179 
180 #endif // INCLUDED_TrackingSystem_h_GUID_B94B2C23_321F_45B4_5167_CB32D2624B50
LedUpdateCount const & updateLedsFromVideoData(ImageOutputDataPtr &&imageData)
This is the second phase of the video-based tracking algorithm - the part that actually changes LED s...
Definition: TrackingSystem.cpp:90
BodyIndices const & processFrame(util::time::TimeValue const &tv, cv::Mat const &frame, cv::Mat const &frameGray, CameraParameters const &camParams)
All parts of the tracking algorithm combined for convenience.
Definition: TrackingSystem.h:107
Eigen::Isometry3d const & getCameraPose() const
This gets rTc - the pose of the camera in the room.
Definition: TrackingSystem.cpp:229
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
std::pair< BodyId, TargetId > BodyTargetId
Type-safe zero-based target ID qualified with its body ID.
Definition: BodyIdTypes.h:67
Definition: CameraParameters.h:41
Header wrapping include of <Eigen/Core> and <Eigen/Geometry> for warning quieting.
Header defining specializations of std::hash that forward to the contained integer type...
Private implementation structure for TrackingSystem.
Definition: TrackingSystem_Impl.h:49
void setUseIMU(bool useIMU)
Definition: TrackingSystem.h:135
ConfigParams const & getParams() const
Definition: TrackingSystem.h:132
Eigen::Isometry3d const & getRoomToCamera() const
This gets cTr - the inverse of the camera pose, transforms from the room coordinate system to the cam...
Definition: TrackingSystem.cpp:233
Definition: TrackingSystem.h:54
BodyIndices const & updateBodiesFromVideoData(ImageOutputDataPtr &&imageData)
The combined second and third phases of the video-based tracking algorithm.
Definition: TrackingSystem.cpp:115
Corresponds to a rigid arrangements of discrete beacons detected by video-based tracking - typically ...
Definition: TrackedBodyTarget.h:77
bool isRoomCalibrationComplete()
Definition: TrackingSystem.cpp:237
Definition: TrackingDebugDisplay.h:54
IMUInputParams imu
IMU input-related parameters.
Definition: ConfigParams.h:254
General configuration parameters.
Definition: ConfigParams.h:82
Header providing a C++ wrapper around TimeValueC.h.
This is the class representing a tracked rigid body in the system.
Definition: TrackedBody.h:56
Definition: Quaternion.h:47
Standardized, portable parallel to struct timeval for representing both absolute times and time inter...
Definition: TimeValueC.h:81
void calibrationHandleIMUData(BodyId id, util::time::TimeValue const &tv, Eigen::Quaterniond const &quat)
Called by TrackedBody::incorporateNewMeasurementFromIMU() if room calibration is not complete...
Definition: TrackingSystem.cpp:212
Definition: Transform.h:43
bool useOrientation
Should orientation reports be used once calibration completes?
Definition: ConfigParams.h:52