KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
psi_skeleton.h
Go to the documentation of this file.
1 /* =========================================================================== *
2  |
3  | Copyright (c) 1994-2011 by Kobus Barnard (author)
4  |
5  | Personal and educational use of this code is granted, provided that this
6  | header is kept intact, and that the authorship is not misrepresented, that
7  | its use is acknowledged in publications, and relevant papers are cited.
8  |
9  | For other use contact the author (kobus AT cs DOT arizona DOT edu).
10  |
11  | Please note that the code in this file has not necessarily been adequately
12  | tested. Naturally, there is no guarantee of performance, support, or fitness
13  | for any particular task. Nonetheless, I am interested in hearing about
14  | problems that you encounter.
15  |
16  | Author: Jinyan Guan
17  * =========================================================================== */
18 
19 /* $Id: psi_skeleton.h 18278 2014-11-25 01:42:10Z ksimek $ */
20 
21 
22 #ifndef PSI_HUMAN_BODY_PARTS_H
23 #define PSI_HUMAN_BODY_PARTS_H
24 
25 #include <vector>
26 #include <iostream>
27 
29 //#include <psi_cpp/psi_util.h>
30 #include <psi_cpp/psi_bbox.h>
32 
33 #include <l_cpp/l_exception.h>
34 
35 #include <string>
36 namespace kjb
37 {
38 namespace psi
39 {
40 
42 
47 {
49  : box(Bbox()),
50  lost(1),
51  occluded(1),
52  label("NONE")
53  {}
54 
56  (
57  const Bbox& box_,
58  int lost_,
59  int occluded_,
60  const std::string& label_
61  ) : box(box_),
62  lost(lost_),
63  occluded(occluded_),
64  label(label_)
65  {}
66 
72  inline
74  (
75  const Perspective_camera& camera,
76  const Bbox& body_box,
77  size_t image_width,
78  size_t image_height
79  ) const
80  {
81  Bbox body(body_box);
82  Bbox part(box);
83  pt::standardize(body, image_width, image_height);
84  pt::standardize(part, image_width, image_height);
85 
86  Vector body_bottom(body.get_bottom_center());
87  body_bottom[0] = part.get_center()[0];
88  double part_height_3d = get_3d_height(body_bottom, part.get_center(), camera);
89 
90  Ground_back_projector back_project(camera, 0.0);
91  Vector pos_3d = back_project(body_bottom[0], body_bottom[1]);
92  if(pos_3d.empty())
93  return pos_3d;
94  Vector part_pos_3d(pos_3d);
95  part_pos_3d[1] = part_height_3d;
96 
97  return part_pos_3d;
98  }
99 
101  int lost;
102  int occluded;
103  std::string label;
104 
105 };
106 
110 class Psi_skeleton : public std::vector<Psi_body_part>
111 {
112 private:
113  typedef std::vector<Psi_body_part> Base;
114  friend std::ostream& operator<<(std::ostream& ost, const Psi_skeleton& skeleton);
115  friend std::istream& operator<<(std::istream& ist, const Psi_skeleton& skeleton);
116 
117 public:
119  Base(11)
120  {}
121 
123 
124  void set_body_part(Body_part_entity body_part, const Psi_body_part& part)
125  {
126  (*this)[body_part] = part;
127  }
128 
129  const Psi_body_part& get_body_part(const std::string& label) const
130  {
131  Body_part_entity body_part = get_body_part_entity(label);
132  return (*this)[body_part];
133  }
134 
135  Body_part_entity get_body_part_entity(const std::string& label) const;
136 
137  void set_body_part(const std::string& label, const Psi_body_part& body_part);
138 
139 };
140 
142 inline
143 std::ostream& operator<<(std::ostream& ost, const Psi_body_part& part)
144 {
145  std::streamsize w = ost.width();
146  std::streamsize p = ost.precision();
147  std::ios::fmtflags f = ost.flags();
148  ost << std::scientific;
149 
150  const Bbox& box = part.box;
151  Vector offset(box.get_width()/2.0, box.get_height()/2.0);
152  Vector tl = box.get_center() - offset;
153  Vector br = box.get_center() + offset;
154 
155  ost << part.label << " "<< part.lost << " "
156  << part.occluded << " " << tl << " " << br;
157 
158  ost.width( w );
159  ost.precision( p );
160  ost.flags( f );
161 
162  return ost;
163 }
164 
166 /*inline
167 std::istream& operator>>(const std::istream& ist, Psi_body_part& part)
168 {
169  ist >> part.label;
170  ist >> part.lost;
171  ist >> part.occluded;
172  ist >> part.box;
173 }
174 */
175 
177 std::ostream& operator<<(std::ostream& out, const Psi_skeleton& skeleton);
178 
180 //std::istream& operator>>(const std::istream& in, Psi_skeleton& skeleton);
181 
182 std::vector<Psi_skeleton> parse_skeleton(std::istream& ist);
183 
184 }// namespace psi
185 }// namespace kjb
186 
187 #endif /*PSI_HUMAN_SKELETON_H */
void set_body_part(Body_part_entity body_part, const Psi_body_part &part)
Definition: psi_skeleton.h:124
Definition: psi_skeleton.h:41
double get_width() const
returns the width of this bounding box
Definition: gr_2D_bounding_box.h:86
int occluded
Definition: psi_skeleton.h:102
Skeleton class, a vector of body parts.
Definition: psi_skeleton.h:110
Definition: psi_skeleton.h:41
std::ostream & operator<<(std::ostream &ost, const Action &action)
serialize an action
Definition: psi_action.cpp:333
Class that represents an axis-aligned 2D rectangle. It is defined in terms of its (2D) center...
Definition: gr_2D_bounding_box.h:51
Definition: psi_skeleton.h:41
bool empty() const
Returns true iff size is zero. Required to comply with stl Container concept.
Definition: m_vector.h:526
Bbox box
Definition: psi_skeleton.h:100
Definition: psi_skeleton.h:41
Definition: psi_skeleton.h:41
Definition: psi_skeleton.h:41
double get_height() const
returns the height of this bounding box
Definition: gr_2D_bounding_box.h:92
Definition: camera_backproject.h:113
friend std::ostream & operator<<(std::ostream &ost, const Psi_skeleton &skeleton)
read in Psi_body_part from stream
Definition: psi_skeleton.cpp:59
const Psi_body_part & get_body_part(const std::string &label) const
Definition: psi_skeleton.h:129
This class implements vectors, in the linear-algebra sense, with real-valued elements.
Definition: m_vector.h:87
Definition: psi_skeleton.h:41
Definition: psi_skeleton.h:41
Body parts.
Definition: psi_skeleton.h:46
~Psi_skeleton()
Definition: psi_skeleton.h:122
Definition: perspective_camera.h:93
std::string label
Definition: psi_skeleton.h:103
Psi_skeleton()
Definition: psi_skeleton.h:118
const Vector & get_center() const
returns the center of this Axis_aligned_rectangle_2d
Definition: gr_2D_bounding_box.h:80
Definition: psi_skeleton.h:41
Vector get_3d_location(const Perspective_camera &camera, const Bbox &body_box, size_t image_width, size_t image_height) const
Get the face position in 3D based on the body 2D bounding box Note: Since the face_box and body_box a...
Definition: psi_skeleton.h:74
int lost
Definition: psi_skeleton.h:101
Body_part_entity get_body_part_entity(const std::string &label) const
Definition: psi_skeleton.cpp:48
Body_part_entity
Definition: psi_skeleton.h:41
void standardize(Vector &v, double cam_width, double cam_height)
Changes Vector to standard (camera) coordinate system.
Definition: pt_util.h:47
Psi_body_part()
Definition: psi_skeleton.h:48
Support for error handling exception classes in libKJB.
double get_3d_height(const Vector &bottom_2d, const Vector &top_2d, const Perspective_camera &camera)
Back project the 2d points to find the height in 3D. Assume that the bottom is on the ground...
Definition: camera_backproject.h:177
Definition: psi_skeleton.h:41
Vector get_bottom_center() const
Definition: gr_2D_bounding_box.h:105
std::vector< Psi_skeleton > parse_skeleton(std::istream &ist)
read skeleton from stream
Definition: psi_skeleton.cpp:93
Definition: psi_skeleton.h:41