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;
72 };
73
75 {
76 Eigen::Vector2f center;
79 };
80
82 {
84 std::optional<std::string> trackingId = std::nullopt;
88 };
89
96
103
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
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
static Duration MilliSeconds(std::int64_t milliSeconds)
Constructs a duration in milliseconds.
Definition Duration.cpp:48
Represents a point in time.
Definition DateTime.h:25
Represents a duration.
Definition Duration.h:17
The HumanFilter class can be used to track and filter the state of a single human.
Definition HumanFilter.h:47
void update(const CameraMeasurement &measurements)
HumanTracker::update Updates the tracked humans with the human measurements from a camera.
void reset()
HumanTracker::reset Resets this instance to the same state as if it just would have been created.
std::vector< human::Human > getTrackedHumans() const
HumanTracker::getTrackedHumans Returns all humans that are currently tracked.
Eigen::Isometry2f Pose2D
Definition basic_types.h:34
This file is part of ArmarX.
memory::LaserScannerFeature Cluster
std::vector< armem::human::HumanPose > humanPoses