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