33 Eigen::Vector3f sumPosition = Eigen::Vector3f::Zero();
35 for (
const auto& [
id, keypoint] : humanPose.
keypoints)
41 sumPosition += keypoint.positionCamera.toEigen();
49 if (keypoint.positionGlobal)
51 sumPosition += keypoint.positionGlobal.value().toEigen();
58 if (keypoint.positionRobot)
60 sumPosition += keypoint.positionRobot.value().toEigen();
76 sumPosition.z() = 0.0;
79 return sumPosition / sumWeights;
86 std::optional<HumanPose> nearestHumanPose = std::nullopt;
87 double minDistance = std::numeric_limits<double>::infinity();
88 for (
const HumanPose& humanPose : humanPoses)
90 if (parameters.
modelIDs.empty() or parameters.
modelIDs.count(humanPose.poseModelId))
92 const std::optional<Eigen::Vector3f> meanPosition =
102 nearestHumanPose = humanPose;
110 return nearestHumanPose;
169 const std::vector<std::vector<Joints>> jointCandidates{
170 {Joints::ShoulderLeft, Joints::ShoulderRight},
171 {Joints::HipLeft, Joints::HipRight},
172 {Joints::EarLeft, Joints::EarRight},
173 {Joints::KneeLeft, Joints::KneeRight}};
175 const auto toString = [](
const std::vector<Joints>& joints)
177 const auto toString = [](
const Joints& joint)
180 return joints | ranges::views::transform(toString) | ranges::to_vector;
183 const std::vector<std::vector<std::string>> candidates =
184 jointCandidates | ranges::views::transform(toString) | ranges::to_vector;
187 std::vector<std::string> suitableKeypoints;
188 for (
const auto& candidate : candidates)
192 ARMARX_INFO <<
"Chosen candidates for pose direction: " << candidate;
193 suitableKeypoints = candidate;
199 if (suitableKeypoints.empty())
208 const auto& kpLeft = pose.
keypoints.at(suitableKeypoints.at(0));
209 const auto& kpRight = pose.
keypoints.at(suitableKeypoints.at(1));
217 const Eigen::Vector3f posLeftGlobal = kpLeft.positionGlobal.value().toEigen();
218 const Eigen::Vector3f posRightGlobal = kpRight.positionGlobal.value().toEigen();
220 const Eigen::Vector3f leftToRightGlobal = posRightGlobal - posLeftGlobal;
223 Eigen::Vector3f forwardDirectionOfHumanGlobal =
224 Eigen::AngleAxisf(M_PI_2, Eigen::Vector3f::UnitZ()) * leftToRightGlobal;
227 forwardDirectionOfHumanGlobal.z() = 0.0f;
230 forwardDirectionOfHumanGlobal.normalize();
232 return forwardDirectionOfHumanGlobal;
239 for (
const auto& [u, v] : pose.
keypoints)
242 if (v.positionGlobal.has_value())
245 auto elem = std::find(labels.begin(), labels.end(), u);
248 if (elem == labels.end())
255 if (v.confidence < threshold)
269 return labels.empty();
275 const std::optional<Eigen::Vector3f> meanPositionGlobal =
277 if (not meanPositionGlobal)
282 Eigen::Isometry2f global_T_human = Eigen::Isometry2f::Identity();
283 global_T_human.translation() = meanPositionGlobal->head<2>();
284 const std::optional<Eigen::Vector3f> directionOfHuman =
286 if (not directionOfHuman)
291 const float yaw = std::atan2(directionOfHuman->y(), directionOfHuman->x());
292 global_T_human.linear() = Eigen::Rotation2Df(yaw).toRotationMatrix();
294 return global_T_human;
const std::string ModelId
const simox::meta::EnumNames< Joints > JointNames
Names of the joints as defined in the body model.
Joints
Joints with index as defined in the body model.