body.h
Go to the documentation of this file.
1 // Copyright 2022 PAL Robotics S.L.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 //
9 // * Redistributions in binary form must reproduce the above copyright
10 // notice, this list of conditions and the following disclaimer in the
11 // documentation and/or other materials provided with the distribution.
12 //
13 // * Neither the name of the PAL Robotics S.L. nor the names of its
14 // contributors may be used to endorse or promote products derived from
15 // this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 // POSSIBILITY OF SUCH DAMAGE.
28 
29 
30 #ifndef HRI_BODY_H
31 #define HRI_BODY_H
32 
33 #include <geometry_msgs/TransformStamped.h>
34 #include <sensor_msgs/Image.h>
35 #include <hri_msgs/Skeleton2D.h>
36 #include <hri_msgs/NormalizedPointOfInterest2D.h>
37 #include <hri_msgs/NormalizedRegionOfInterest2D.h>
38 #include <memory>
39 #include <boost/optional.hpp>
40 
41 #include "base.h"
42 #include "ros/subscriber.h"
43 
44 #include <opencv2/core.hpp>
45 
47 
48 typedef hri_msgs::NormalizedRegionOfInterest2D NormROI;
49 typedef hri_msgs::NormalizedPointOfInterest2D SkeletonPoint;
50 
51 namespace hri
52 {
53 // the tf prefix follows REP-155
54 const static std::string BODY_TF_PREFIX("body_");
55 const static ros::Duration BODY_TF_TIMEOUT(0.01);
56 
57 class Body : public FeatureTracker
58 {
59 public:
60  Body(ID id, ros::NodeHandle& nh, tf2_ros::Buffer* tf_buffer_ptr,
61  const std::string& reference_frame);
62 
63  virtual ~Body();
64 
67  std::string frame() const
68  {
69  return BODY_TF_PREFIX + id_;
70  }
71 
95  NormROI roi() const;
96 
99  cv::Mat cropped() const;
100 
109  std::vector<SkeletonPoint> skeleton() const;
110 
113  boost::optional<geometry_msgs::TransformStamped> transform() const;
114 
115  void init() override;
116 
117 private:
118  size_t nb_roi;
119 
121  void onRoI(hri_msgs::NormalizedRegionOfInterest2DConstPtr roi);
123 
125  void onCropped(sensor_msgs::ImageConstPtr roi);
126  cv::Mat cropped_;
127 
129  void onSkeleton(hri_msgs::Skeleton2DConstPtr skeleton);
130  std::vector<SkeletonPoint> skeleton_;
131 
132  std::string _reference_frame;
134 };
135 
136 typedef std::shared_ptr<Body> BodyPtr;
137 typedef std::shared_ptr<const Body> BodyConstPtr;
138 typedef std::weak_ptr<Body> BodyWeakPtr;
139 typedef std::weak_ptr<const Body> BodyWeakConstPtr;
140 
141 } // namespace hri
142 #endif
hri::Body::skeleton_
std::vector< SkeletonPoint > skeleton_
Definition: body.h:130
hri
Definition: base.h:38
hri::FeatureTracker
Definition: base.h:52
hri::BodyWeakPtr
std::weak_ptr< Body > BodyWeakPtr
Definition: body.h:138
hri::Body::cropped_
cv::Mat cropped_
Definition: body.h:126
NormROI
hri_msgs::NormalizedRegionOfInterest2D NormROI
Definition: body.h:48
hri::Body::nb_roi
size_t nb_roi
Definition: body.h:118
hri::Body::skeleton
std::vector< SkeletonPoint > skeleton() const
Returns the 2D skeleton keypoints.
Definition: body.cpp:89
hri::BODY_TF_PREFIX
const static std::string BODY_TF_PREFIX("body_")
base.h
hri::Body::roi_
NormROI roi_
Definition: body.h:122
hri::BodyPtr
std::shared_ptr< Body > BodyPtr
Definition: body.h:136
hri::BODY_TF_TIMEOUT
const static ros::Duration BODY_TF_TIMEOUT(0.01)
hri::Body::init
void init() override
Definition: body.cpp:49
hri::Body::_reference_frame
std::string _reference_frame
Definition: body.h:132
subscriber.h
hri::Body::Body
Body(ID id, ros::NodeHandle &nh, tf2_ros::Buffer *tf_buffer_ptr, const std::string &reference_frame)
Definition: body.cpp:36
hri::Body::_tf_buffer_ptr
tf2_ros::Buffer * _tf_buffer_ptr
Definition: body.h:133
hri::BodyConstPtr
std::shared_ptr< const Body > BodyConstPtr
Definition: body.h:137
hri::BodyWeakConstPtr
std::weak_ptr< const Body > BodyWeakConstPtr
Definition: body.h:139
hri::Body::onCropped
void onCropped(sensor_msgs::ImageConstPtr roi)
Definition: body.cpp:74
tf2_ros::Buffer
SkeletonPoint
hri_msgs::NormalizedPointOfInterest2D SkeletonPoint
Definition: body.h:49
transform_listener.h
hri::Body::skeleton_subscriber_
ros::Subscriber skeleton_subscriber_
Definition: body.h:128
hri::Body::roi_subscriber_
ros::Subscriber roi_subscriber_
Definition: body.h:120
hri::Body::~Body
virtual ~Body()
Definition: body.cpp:43
hri::Body::roi
NormROI roi() const
If available, returns the normalized 2D region of interest (RoI) of the body.
Definition: body.cpp:69
hri::Body::onRoI
void onRoI(hri_msgs::NormalizedRegionOfInterest2DConstPtr roi)
Definition: body.cpp:64
hri::Body::transform
boost::optional< geometry_msgs::TransformStamped > transform() const
Returns the (stamped) 3D transform of the body (if available).
Definition: body.cpp:94
hri::Body::frame
std::string frame() const
the name of the tf frame that correspond to this body
Definition: body.h:67
hri::ID
std::string ID
Definition: base.h:40
hri::Body::onSkeleton
void onSkeleton(hri_msgs::Skeleton2DConstPtr skeleton)
Definition: body.cpp:84
hri::Body::cropped_subscriber_
ros::Subscriber cropped_subscriber_
Definition: body.h:124
ros::Duration
hri::Body::cropped
cv::Mat cropped() const
Returns the body image, cropped from the source image.
Definition: body.cpp:79
hri::Body
Definition: body.h:57
ros::NodeHandle
ros::Subscriber
hri::FeatureTracker::id_
ID id_
Definition: base.h:116


libhri
Author(s): Séverin Lemaignan
autogenerated on Thu Jul 6 2023 02:43:58