OpenPoseEstimationUtil.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 * @package <PACKAGE_NAME>::<CATEGORY>::Util
17 * @author Stefan Reither ( stef dot reither at web dot de )
18 * @date 2018
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
24
26
27using namespace armarx;
28
29namespace visionx
30{
31 // Mapping from labels used in topic from SecondHands to corresponding ids and labals in the MPI-Model
32 const std::map<std::string, std::pair<unsigned int, std::string>> MPII_TO_MPI{
33 {"head", {0, "Head"}},
34 {"neck", {1, "Neck"}},
35 {"right_shoulder", {2, "RShoulder"}},
36 {"right_elbow", {3, "RElbow"}},
37 {"right_hand", {4, "RWrist"}},
38 {"left_shoulder", {5, "LShoulder"}},
39 {"left_elbow", {6, "LElbow"}},
40 {"left_hand", {7, "LWrist"}},
41 {"right_waist", {8, "RHip"}},
42 {"right_knee", {9, "RKnee"}},
43 {"right_foot", {10, "RAnkle"}},
44 {"left_waist", {11, "LHip"}},
45 {"left_knee", {12, "LKnee"}},
46 {"left_foot", {13, "LAnkle"}},
47 };
48
49 struct Polygon2D
50 {
51 struct Point
52 {
53 float x;
54 float y;
55
56 bool
57 operator==(const Point& p) const
58 {
59 return this->x - p.x < std::numeric_limits<float>::epsilon() &&
60 this->y - p.y < std::numeric_limits<float>::epsilon();
61 }
62 };
63
64 using PointList = std::vector<Point>;
65 // ordered list of polygon points
66 // assert(points[0] == points[n]
67 std::vector<Point> points;
68
70 {
71 }
72
74 {
76 this->points = points;
77 }
78
79 // isLeft(): tests if a point is Left|On|Right of an infinite line.
80 // Input: three points p0, p1, and p2
81 // Return: >0 for p2 left of the line through p0 and p1
82 // =0 for p2 on the line
83 // <0 for p2 right of the line
84 int
85 isLeft(Point p0, Point p1, Point p2) const
86 {
87 return static_cast<int>((p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y));
88 }
89
90 // Algorithm from http://geomalgorithms.com/a03-_inclusion.html#wn_PnPoly() (Date: 05/16/2018)
91 bool
93 {
94 Point p;
95 p.x = point->x;
96 p.y = point->y;
97 int wn = 0; // the winding number counter
98 // loop through all edges of the polygon
99 for (unsigned int i = 0; i < points.size() - 1; i++) // edge from V[i] to V[i+1]
100 {
101 if (points[i].y <= p.y) // start y <= P.y
102 {
103 if (points[i + 1].y > p.y) // an upward crossing
104 if (isLeft(points[i], points[i + 1], p) > 0) // P left of edge
105 {
106 ++wn; // have a valid up intersect
107 }
108 }
109 else // start y > P.y (no test needed)
110 {
111 if (points[i + 1].y <= p.y) // a downward crossing
112 if (isLeft(points[i], points[i + 1], p) < 0) // P right of edge
113 {
114 --wn; // have a valid down intersect
115 }
116 }
117 }
118 return wn == 1;
119 }
120 };
121} // namespace visionx
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< FramedPosition > FramedPositionPtr
Definition FramedPose.h:149
ArmarX headers.
const std::map< std::string, std::pair< unsigned int, std::string > > MPII_TO_MPI
bool operator==(const Point &p) const
Polygon2D(PointList points)
std::vector< Point > points
bool isInside(FramedPositionPtr point) const
int isLeft(Point p0, Point p1, Point p2) const
std::vector< Point > PointList