KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
psi_skeleton_detection.h
Go to the documentation of this file.
1 /* $Id: psi_skeleton_detection.h 17393 2014-08-23 20:19:14Z predoehl $ */
2 /* {{{=========================================================================== *
3  |
4  | Copyright (c) 1994-2011 by Kobus Barnard (author)
5  |
6  | Personal and educational use of this code is granted, provided that this
7  | header is kept intact, and that the authorship is not misrepresented, that
8  | its use is acknowledged in publications, and relevant papers are cited.
9  |
10  | For other use contact the author (kobus AT cs DOT arizona DOT edu).
11  |
12  | Please note that the code in this file has not necessarily been adequately
13  | tested. Naturally, there is no guarantee of performance, support, or fitness
14  | for any particular task. Nonetheless, I am interested in hearing about
15  | problems that you encounter.
16  |
17  | Author: Jinyan Guan
18  * =========================================================================== }}}*/
19 
20 // vim: tabstop=4 shiftwidth=4 foldmethod=marker
21 
22 #ifndef PSI_SKELETON_DETECTION_H
23 #define PSI_SKELETON_DETECTION_H
24 
25 #include <vector>
26 #include <iostream>
27 
28 #include <psi_cpp/psi_util.h>
29 #include <psi_cpp/psi_bbox.h>
30 
31 #include <l_cpp/l_exception.h>
32 
33 #include <string>
34 namespace kjb
35 {
36 namespace psi
37 {
38 
42 class Skeleton_detection : public std::vector<Bbox>
43 {
44 private:
45  typedef std::vector<Bbox> Base;
46  double score;
47  friend std::ostream& operator<<(std::ostream& ost, const Skeleton_detection& skeleton);
48  friend std::istream& operator<<(std::istream& ist, const Skeleton_detection& skeleton);
49 
50 public:
52  Base(26),
53  score(-DBL_MAX)
54  {}
55 
57 
58  void set_body_part(size_t body_part, const Bbox& part)
59  {
60  (*this)[body_part] = part;
61  }
62 
63  void set_score(double score_)
64  {
65  score = score_;
66  }
67 
68  const Bbox& get_body_part(size_t body_part) const
69  {
70  return (*this)[body_part];
71  }
72 
73  double get_score() const
74  {
75  return score;
76  }
77 
78  Bbox get_bounding_box() const;
79 };
80 
82 inline
83 std::ostream& operator<<(std::ostream& ost, const Skeleton_detection& skeleton)
84 {
85  std::streamsize w = ost.width();
86  std::streamsize p = ost.precision();
87  std::ios::fmtflags f = ost.flags();
88  //ost << std::scientific;
89 
90  Skeleton_detection::const_iterator it;
91  for(it = skeleton.begin(); it < skeleton.end(); it++)
92  {
93  Bbox box(*it);
94  Vector offset(box.get_width()/2.0, box.get_height()/2.0);
95  Vector tl = box.get_center() - offset;
96  Vector br = box.get_center() + offset;
97 
98  ost << tl[0] << " " << tl[1] << " "
99  << br[0] << " " << br[1] << " ";
100  }
101  ost << skeleton.get_score();
102 
103  ost.width( w );
104  ost.precision( p );
105  ost.flags( f );
106 
107  return ost;
108 }
109 
110 std::vector<Skeleton_detection> parse_skeleton_detection(std::istream& ist);
111 
112 }// namespace psi
113 }// namespace kjb
114 
115 #endif /*PSI_SKELETON_DETECTION_H */
double get_width() const
returns the width of this bounding box
Definition: gr_2D_bounding_box.h:86
double get_score() const
Definition: psi_skeleton_detection.h:73
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
double get_height() const
returns the height of this bounding box
Definition: gr_2D_bounding_box.h:92
~Skeleton_detection()
Definition: psi_skeleton_detection.h:56
This class implements vectors, in the linear-algebra sense, with real-valued elements.
Definition: m_vector.h:87
friend std::ostream & operator<<(std::ostream &ost, const Skeleton_detection &skeleton)
writes part into out stream
Definition: psi_skeleton_detection.h:83
const Vector & get_center() const
returns the center of this Axis_aligned_rectangle_2d
Definition: gr_2D_bounding_box.h:80
Skeleton class, a vector of body parts.
Definition: psi_skeleton_detection.h:42
void set_score(double score_)
Definition: psi_skeleton_detection.h:63
Bbox get_bounding_box() const
Definition: psi_skeleton_detection.cpp:35
std::vector< Skeleton_detection > parse_skeleton_detection(std::istream &ist)
Definition: psi_skeleton_detection.cpp:57
Support for error handling exception classes in libKJB.
Skeleton_detection()
Definition: psi_skeleton_detection.h:51
void set_body_part(size_t body_part, const Bbox &part)
Definition: psi_skeleton_detection.h:58
const Bbox & get_body_part(size_t body_part) const
Definition: psi_skeleton_detection.h:68