HumanTracker.h
Go to the documentation of this file.
1 /**
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @author Tobias Gröger ( tobias dot groeger at student dot kit dot edu )
17  * @author Corvin Navarro Ecker ( corvin dot ecker at student dot kit dot edu )
18  * @date 2022
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 #pragma once
24 
25 #include <ArmarXCore/core/time.h>
26 
28 
34 
36 
38 {
40 
41  /**
42  * @brief The HumanTracker class can be used to track and filter multiple humans. It hides
43  * implementation detail on how new detected humans are associated to the old, already tracked
44  * humans. New detected humans can be fed by using the update method. The tracked humans can
45  * be obtained using the getTrackedHumans method.
46  */
48  {
49  public:
50  HumanTracker() = default;
51 
53  {
55  std::vector<armem::human::HumanPose> humanPoses;
56  };
57 
59  {
61  std::vector<Cluster> clusters;
62  };
63 
65  {
67  std::optional<std::string> trackingId;
69  bool associated;
70  };
71 
73  {
74  Eigen::Vector2f center;
76  bool associated;
77  };
78 
79  struct TrackedHuman
80  {
82  std::optional<std::string> trackingId = std::nullopt;
84  bool associated;
86  };
87 
89  {
92  float distance;
93  };
94 
96  {
99  float distance;
100  };
101 
102  struct Parameters
103  {
104  // the keypoint which should be used for calculating the rotation of the humans
105  const std::string rotationKeypoint = "Head";
106  // the duration after which tracked humans will be erased if no new measurement for
107  // this human is found
109  // the maximum distance in millimeters of two human measurements where they are still
110  // associated with each other
112  // the maximum size (aka length) in millimeters a footprint can have
113  float maxFootprintSize = 350;
114  // alpha value from interval [0,1] to determine how much the current (and respectively
115  // the old) velocity should be weighted when calculating the new velocity
116  float velocityAlpha = 0.7;
117 
118  int confidenceCamera = 100;
119  int confidenceLaser = -2;
120 
121  // whether to use the kalman filter inside the HumanFilter
122  bool useKalmanFilter = false;
123  };
124 
125  /**
126  * @brief HumanTracker::update Updates the tracked humans with the human measurements from a camera. When a
127  * measurement is close enough to an existing tracked human, they are associated, otherwise a
128  * new tracked human is created. Tracked humans that were not associated with a new measurement
129  * for a specified amount of time are removed. New associated measurements for a tracked human
130  * are always filtered to provide a less noisy state.
131  * @param measurements the new measurements of the environment
132  */
133  void update(const CameraMeasurement& measurements);
134  /**
135  * @brief HumanTracker::update Updates the tracked humans with the measurements from a lasersensor.
136  * When a measurement is close enough to an existing tracked human, they are associated,
137  * otherwise the measurement is not used for human tracking but returned in the list of unused
138  * measurements. Tracked humans that were not associated with a new measurement for a
139  * specified amount of time are removed. New associated measurements for a tracked human
140  * are always filtered to provide a less noisy state.
141  * @param measurements
142  * @return
143  */
144  std::vector<Cluster> update(const LaserMeasurement& measurements);
145  /**
146  * @brief HumanTracker::getTrackedHumans Returns all humans that are currently tracked.
147  * @return the tracked humans
148  */
149  std::vector<human::Human> getTrackedHumans() const;
150  /**
151  * @brief HumanTracker::reset Resets this instance to the same state as if it just would have
152  * been created.
153  */
154  void reset();
155 
156  private:
157  /**
158  * @brief convertHumanPoseToDetectedHuman Sets every parameter of a detected human according
159  * to the human pose and returns the new created detected human.
160  * @param time the time of detection
161  * @param humanPose the human pose representing the human
162  * @return the new created detected human
163  */
164  DetectedHuman convertHumanPoseToDetectedHuman(const DateTime& time,
165  const armem::human::HumanPose& humanPose);
166  /**
167  * @brief getSortedDistances Returns a sorted vector of the distances between every possible
168  * combination (T, D) where T is an old, tracked human and D is a new, detected human and
169  * both of them are not already associated. The smallest distance will be the first entry in
170  * the vector.
171  * @param oldHumans the old, tracked humans
172  * @param newHumans the new, detected humans
173  * @return the sorted vector of distances with references to the according humans
174  */
175  std::vector<PosHumanDistance>
176  getSortedDistances(std::vector<HumanTracker::TrackedHuman>& oldHumans,
177  std::vector<HumanTracker::DetectedHuman>& newHumans);
178  /**
179  * @brief getSortedDistances Returns a sorted vector of the distances between every possible
180  * combination (T, C) where T is an old, tracked human and C is a new, detected cluster.
181  * The smallest distance will be the first entry in the vector.
182  * @param oldHumans
183  * @param newClusters
184  * @return
185  */
186  std::vector<PosLaserDistance>
187  getSortedDistances(std::vector<HumanTracker::TrackedHuman>& oldHumans,
188  std::vector<AdvancedCluster>& newClusters);
189  /**
190  * @brief HumanTracker::associateHumans Associates those tracked and detected humans that
191  * belong together.
192  * @param detectedHumans The detected humans against which the saved list of tracked humans is
193  * matched.
194  */
195  void associateHumans(std::vector<DetectedHuman>& detectedHumans);
196  /**
197  * @brief HumanTracker::associate Associates the given tracked and detected human. Therefore it
198  * updates all necessary variables of the TrackedHuman
199  * @param trackedHuman the tracked human
200  * @param detectedHuman the detected human
201  */
202  void associate(TrackedHuman* tracked, DetectedHuman* detected);
203  /**
204  * @brief getClusterSize Returns the size of the given cluster. That is for now the maximum
205  * distance between two points.
206  * @param cluster The cluster whose size is measured
207  * @return the size
208  */
209  float getClusterSize(Cluster cluster);
210  /**
211  * @brief HumanTracker::getClusterCenter Returns the center of the given cluster. That is
212  * calculated as the mean of all points.
213  * @param cluster The cluster whose center is calculated
214  * @return the center
215  */
216  Eigen::Vector2f getClusterCenter(Cluster cluster);
217  /**
218  * @brief prepareTrackedHumans Deletes all tracked humans that received no update for too
219  * long. All remaining tracked humans are prepared for association with the given point in
220  * time.
221  */
222  void prepareTrackedHumans(DateTime time);
223 
224 
225  private:
226  std::vector<TrackedHuman> trackedHumans;
227  Parameters parameters;
228  };
229 } // namespace armarx::navigation::human
armarx::navigation::human::HumanTracker::DetectedHuman::detectionTime
DateTime detectionTime
Definition: HumanTracker.h:68
armarx::navigation::human::HumanTracker::getTrackedHumans
std::vector< human::Human > getTrackedHumans() const
HumanTracker::getTrackedHumans Returns all humans that are currently tracked.
Definition: HumanTracker.cpp:152
HumanFilter.h
basic_types.h
armarx::navigation::human::HumanTracker::DetectedHuman
Definition: HumanTracker.h:64
armarx::navigation::human::HumanTracker::Parameters::maxAssociationDistance
float maxAssociationDistance
Definition: HumanTracker.h:111
armarx::navigation::human::HumanTracker::PosLaserDistance::newCluster
AdvancedCluster * newCluster
Definition: HumanTracker.h:98
armarx::navigation::human::HumanTracker::Parameters::confidenceCamera
int confidenceCamera
Definition: HumanTracker.h:118
armarx::navigation::human::HumanTracker::LaserMeasurement::detectionTime
DateTime detectionTime
Definition: HumanTracker.h:60
armarx::navigation::human::HumanTracker::TrackedHuman::humanFilter
HumanFilter humanFilter
Definition: HumanTracker.h:81
armarx::navigation::human::HumanTracker::PosHumanDistance
Definition: HumanTracker.h:88
types.h
armarx::navigation::human::HumanTracker::DetectedHuman::pose
core::Pose2D pose
Definition: HumanTracker.h:66
armarx::navigation::human
This file is part of ArmarX.
Definition: aron_conversions.cpp:9
armarx::navigation::human::HumanTracker::reset
void reset()
HumanTracker::reset Resets this instance to the same state as if it just would have been created.
Definition: HumanTracker.cpp:161
armarx::navigation::human::HumanTracker::CameraMeasurement::detectionTime
DateTime detectionTime
Definition: HumanTracker.h:54
armarx::navigation::human::HumanTracker::AdvancedCluster::center
Eigen::Vector2f center
Definition: HumanTracker.h:74
armarx::navigation::human::HumanTracker::PosHumanDistance::newHuman
HumanTracker::DetectedHuman * newHuman
Definition: HumanTracker.h:91
armarx::navigation::core::Pose2D
Eigen::Isometry2f Pose2D
Definition: basic_types.h:34
armarx::navigation::human::HumanTracker::PosHumanDistance::distance
float distance
Definition: HumanTracker.h:92
armarx::navigation::human::HumanTracker::TrackedHuman::trackingId
std::optional< std::string > trackingId
Definition: HumanTracker.h:82
armarx::navigation::human::HumanTracker::TrackedHuman
Definition: HumanTracker.h:79
armarx::navigation::human::HumanTracker::HumanTracker
HumanTracker()=default
armarx::navigation::human::HumanTracker::Parameters::maxFootprintSize
float maxFootprintSize
Definition: HumanTracker.h:113
types.h
armarx::navigation::human::HumanTracker::CameraMeasurement
Definition: HumanTracker.h:52
armarx::navigation::human::HumanTracker::TrackedHuman::associatedCluster
AdvancedCluster * associatedCluster
Definition: HumanTracker.h:83
armarx::navigation::human::HumanTracker::DetectedHuman::associated
bool associated
Definition: HumanTracker.h:69
armarx::navigation::human::HumanTracker::TrackedHuman::associated
bool associated
Definition: HumanTracker.h:84
armarx::armem::human::HumanPose
Definition: types.h:30
armarx::navigation::human::HumanTracker::TrackedHuman::confidence
int confidence
Definition: HumanTracker.h:85
types.h
armarx::navigation::human::HumanTracker::PosHumanDistance::oldHuman
HumanTracker::TrackedHuman * oldHuman
Definition: HumanTracker.h:90
armarx::navigation::human::HumanTracker::AdvancedCluster::cluster
Cluster cluster
Definition: HumanTracker.h:75
armarx::navigation::human::HumanTracker::Parameters::confidenceLaser
int confidenceLaser
Definition: HumanTracker.h:119
armarx::navigation::human::HumanTracker::PosLaserDistance
Definition: HumanTracker.h:95
armarx::core::time::DateTime
Represents a point in time.
Definition: DateTime.h:24
armarx::navigation::human::HumanFilter
The HumanFilter class can be used to track and filter the state of a single human.
Definition: HumanFilter.h:38
armarx::navigation::human::HumanTracker::AdvancedCluster::associated
bool associated
Definition: HumanTracker.h:76
armarx::navigation::human::HumanTracker::LaserMeasurement::clusters
std::vector< Cluster > clusters
Definition: HumanTracker.h:61
armarx::navigation::human::HumanTracker::PosLaserDistance::oldHuman
HumanTracker::TrackedHuman * oldHuman
Definition: HumanTracker.h:97
armarx::navigation::human::HumanTracker::Parameters::useKalmanFilter
bool useKalmanFilter
Definition: HumanTracker.h:122
armarx::core::time::Duration
Represents a duration.
Definition: Duration.h:17
armarx::navigation::human::HumanTracker::Parameters::rotationKeypoint
const std::string rotationKeypoint
Definition: HumanTracker.h:105
armarx::navigation::human::HumanTracker::CameraMeasurement::humanPoses
std::vector< armem::human::HumanPose > humanPoses
Definition: HumanTracker.h:55
armarx::navigation::human::HumanTracker::Parameters::velocityAlpha
float velocityAlpha
Definition: HumanTracker.h:116
armarx::navigation::human::HumanTracker::Parameters
Definition: HumanTracker.h:102
time.h
armarx::navigation::human::HumanTracker::AdvancedCluster
Definition: HumanTracker.h:72
UnscentedKalmanFilter.h
armarx::navigation::memory::LaserScannerFeature
Definition: types.h:47
armarx::navigation::human::HumanTracker::Parameters::maxTrackingAge
Duration maxTrackingAge
Definition: HumanTracker.h:108
armarx::navigation::human::HumanTracker::LaserMeasurement
Definition: HumanTracker.h:58
armarx::navigation::human::HumanTracker
The HumanTracker class can be used to track and filter multiple humans.
Definition: HumanTracker.h:47
armarx::navigation::human::HumanTracker::DetectedHuman::trackingId
std::optional< std::string > trackingId
Definition: HumanTracker.h:67
armarx::navigation::human::HumanTracker::PosLaserDistance::distance
float distance
Definition: HumanTracker.h:99
HumanSystemModel.h
armarx::navigation::human::HumanTracker::update
void update(const CameraMeasurement &measurements)
HumanTracker::update Updates the tracked humans with the human measurements from a camera.
Definition: HumanTracker.cpp:19
armarx::core::time::Duration::MilliSeconds
static Duration MilliSeconds(std::int64_t milliSeconds)
Constructs a duration in milliseconds.
Definition: Duration.cpp:55