54 Keypoint::Keypoint(
const Point2D& point,
unsigned int id,
const std::string& name,
float confidence) : _id(id), _name(name), _dominantColor(DrawColor24Bit {0, 0, 0})
57 setConfidence(confidence);
60 Keypoint::Keypoint(
const Point2D& left,
const Point2D& right,
unsigned int id,
const std::string& name,
float confidence) : _id(id), _name(name), _dominantColor(DrawColor24Bit {0, 0, 0})
62 setStereo2D(left, right);
63 setConfidence(confidence);
68 return _pos3D ? true :
false;
73 return !_pointR.
isnan();
96 _confidence = confidence;
101 _dominantColor = color;
112 return std::make_pair(_pointL, _pointR);
127 return _dominantColor;
142 std::stringstream ss;
144 ss <<
"Name: " << _name <<
", ";
145 ss <<
"x: " << _pointL.
_x <<
", ";
146 ss <<
"y: " << _pointL.
_y <<
", ";
147 ss <<
"Confindence: " << _confidence;
157 return _keypoints.get<0>().
begin();
162 return _keypoints.get<0>().
end();
168 auto itFound = _keypoints.get<1>().find(nodeName);
169 if (itFound != _keypoints.get<1>().end())
181 auto itFound = _keypoints.get<0>().find(
id);
182 if (itFound != _keypoints.get<0>().end())
196 _keypoints.insert(point);
202 _keypoints.get<1>().erase(nodeName);
207 _keypoints.get<0>().erase(
id);
212 return _keypoints.get<0>().
size();
219 return std::numeric_limits<float>::quiet_NaN();
222 int amountDepths = 0;
226 result += point->get3D()->z;
229 return result /
static_cast<float>(amountDepths);
234 Keypoint2DMap iceMap;
235 for (
auto [
id, label] : idNameMap)
240 Keypoint2D iceKeypoint;
241 iceKeypoint.x = keypoint->get2D()._x;
242 iceKeypoint.y = keypoint->get2D()._y;
243 iceKeypoint.label = keypoint->getName();
244 iceKeypoint.confidence = keypoint->getConfidence();
245 iceKeypoint.dominantColor = keypoint->getDominantColor();
246 iceMap.insert(std::make_pair(iceKeypoint.label, iceKeypoint));
250 Keypoint2D iceKeypoint;
251 iceKeypoint.x = 0.0f;
252 iceKeypoint.y = 0.0f;
253 iceKeypoint.label = label;
254 iceKeypoint.confidence = 0.0f;
255 iceKeypoint.dominantColor = DrawColor24Bit {0, 0, 0};
256 iceMap.insert(std::make_pair(iceKeypoint.label, iceKeypoint));
264 Keypoint3DMap iceMap;
265 for (
auto [
id, label] : idNameMap)
268 if (keypoint && keypoint->is3DSet())
270 Keypoint3D iceKeypoint;
271 iceKeypoint.x = keypoint->get3D()->x;
272 iceKeypoint.y = keypoint->get3D()->y;
273 iceKeypoint.z = keypoint->get3D()->z;
275 Eigen::Vector3f globalPose = keypoint->get3D()->toGlobalEigen(local_robot);
277 iceKeypoint.globalX = globalPose(0);
278 iceKeypoint.globalY = globalPose(1);
279 iceKeypoint.globalZ = globalPose(2);
281 iceKeypoint.label = keypoint->getName();
282 iceKeypoint.confidence = keypoint->getConfidence();
283 iceKeypoint.dominantColor = keypoint->getDominantColor();
284 iceMap.insert(std::make_pair(keypoint->getName(), iceKeypoint));
288 Keypoint3D iceKeypoint;
289 iceKeypoint.x = 0.0f;
290 iceKeypoint.y = 0.0f;
291 iceKeypoint.z = 0.0f;
292 iceKeypoint.globalX = 0.0f;
293 iceKeypoint.globalY = 0.0f;
294 iceKeypoint.globalZ = 0.0f;
295 iceKeypoint.label = label;
296 iceKeypoint.confidence = 0.0f;
297 iceKeypoint.dominantColor = DrawColor24Bit {0, 0, 0};
298 iceMap.insert(std::make_pair(iceKeypoint.label, iceKeypoint));
310 KeypointPtr otherPoint =
object->getNode(keypoint->getId());
314 keypoint->setStereo2D(keypoint->get2D(), otherPoint->get2D());
316 keypoint->setConfidence((keypoint->getConfidence() + otherPoint->getConfidence()) / 2.0f);
324 std::stringstream ss;
327 ss << keypoint->toString2D() <<
"\n";
343 Keypoint2DMapList
list;
346 list.push_back(o->toIce2D(_idNameMap));
354 for (Keypoint2DMap map :
list)
356 for (
auto pair : map)
358 Keypoint2D point = pair.second;
359 if (point.x < 0.0f || point.x > width || point.y < 0.0f || point.y > height)
366 point.x = point.x /
static_cast<float>(width);
367 point.y = point.y /
static_cast<float>(height);
376 Keypoint3DMapList
list;
379 list.push_back(o->toIce3D(_idNameMap, local_robot));
393 size_t leftSize =
getData().size();
394 size_t rightSize = other->getData().size();
398 if (leftSize == 0 || rightSize == 0)
403 std::vector<KeypointObjectPtr> moreObjects;
404 std::vector<KeypointObjectPtr> lessObjects;
405 if (leftSize > rightSize)
408 lessObjects = other->getData();
412 moreObjects = other->getData();
417 if (leftSize == 1 && rightSize == 1)
425 Eigen::MatrixXf personDistances(lessObjects.size(), moreObjects.size());
426 Eigen::MatrixXf validKeypointsRatio(lessObjects.size(), moreObjects.size());
428 for (
unsigned int l = 0; l < lessObjects.size(); l++)
431 for (
unsigned int r = 0; r < moreObjects.size(); r++)
435 int addedDistances = 0;
441 sum += std::pow(kpl->get2D()._x - kpr->get2D()._x, 2) + std::pow(kpr->get2D()._y - kpr->get2D()._y, 2);
449 int validKeypointsPL =
static_cast<int>(pl->size());
450 int validKeypointsPR =
static_cast<int>(pr->size());
451 if (validKeypointsPL == 0 || validKeypointsPR == 0)
453 validKeypointsRatio(l, r) = 0.000000001f;
455 else if (validKeypointsPL > validKeypointsPR)
457 validKeypointsRatio(l, r) =
static_cast<float>(validKeypointsPR) /
static_cast<float>(validKeypointsPL);
461 validKeypointsRatio(l, r) =
static_cast<float>(validKeypointsPR) /
static_cast<float>(validKeypointsPL);
467 std::vector<unsigned int> numbers(moreObjects.size());
468 std::iota(numbers.begin(), numbers.end(), 0);
470 std::vector<unsigned int> bestPermutation;
475 for (
unsigned int i = 0; i < lessObjects.size(); i++)
477 sum += personDistances(i, numbers.at(i)) /
static_cast<float>(std::pow(validKeypointsRatio(i, numbers.at(i)), 3));
479 if (sum < currentMin)
482 bestPermutation = numbers;
484 std::reverse(numbers.begin() +
static_cast<long>(lessObjects.size()), numbers.end());
486 while (std::next_permutation(numbers.begin(), numbers.end()));
489 if (!bestPermutation.empty())
491 if (leftSize <= rightSize)
493 for (
unsigned int i = 0; i < this->
getData().size(); i++)
497 left->matchWith(right);
502 for (
unsigned int i = 0; i < other->getData().size(); i++)
506 left->matchWith(right);
514 if (n > _objects.size())
520 return o1->getAverageDepth() < o2->getAverageDepth();