Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 #ifndef _NITE_USER_VIEWER_H_
00069 #define _NITE_USER_VIEWER_H_
00070
00071
00072 #include <libnite2/NiTE.h>
00073 #include <ros/ros.h>
00074 #include <tf/tfMessage.h>
00075 #include <tf/transform_broadcaster.h>
00076 #include <tf/transform_listener.h>
00077 #include <tf/tf.h>
00078
00079 #include <pcl/ros/conversions.h>
00080 #include <pcl_ros/point_cloud.h>
00081 #include <pcl/point_types.h>
00082
00083 #include <visualization_msgs/Marker.h>
00084 #include <cob_perception_msgs/Skeleton.h>
00085 #include <cob_perception_msgs/People.h>
00086 #include <sensor_msgs/image_encodings.h>
00087 #include <sensor_msgs/PointCloud2.h>
00088
00089 #include <image_transport/image_transport.h>
00090 #include <image_transport/subscriber_filter.h>
00091 #include <opencv2/imgproc/imgproc.hpp>
00092 #include <opencv2/highgui/highgui.hpp>
00093
00094 #include <cv_bridge/cv_bridge.h>
00095
00096 #include <boost/thread/mutex.hpp>
00097 #include <boost/timer.hpp>
00098
00099 #include <vector>
00100
00101 #define MAX_DEPTH 10000
00102 typedef std::map<std::string, nite::SkeletonJoint>JointMap;
00103
00104 class BodyTracker
00105 {
00106
00107 public:
00108
00109 BodyTracker(ros::NodeHandle nh);
00110 virtual ~BodyTracker();
00111
00112 std::string tf_prefix_, rel_frame_, depth_optical_frame_;
00113 openni::Device device_;
00114 openni::VideoStream depthSensor_;
00115 void finalize();
00116 void runTracker();
00117
00118 bool shutdown_;
00119
00120 private:
00121
00122
00123 ros::NodeHandle nh_;
00124
00125
00126 tf::TransformListener transform_listener_;
00127 tf::TransformBroadcaster transform_broadcaster_;
00128 ros::Publisher vis_pub_, pcl_pub_, skeleton_pub_, people_pub_;
00129 ros::Subscriber pcl_sub_;
00130 image_transport::ImageTransport* it_;
00131 image_transport::SubscriberFilter image_sub_;
00132
00133 image_transport::Publisher image_pub_;
00134 pcl::PointCloud<pcl::PointXYZRGB>::Ptr pcl_cloud_;
00135 void imgConnectCB(const image_transport::SingleSubscriberPublisher& pub);
00136 void imgDisconnectCB(const image_transport::SingleSubscriberPublisher& pub);
00137
00138 std::list<nite::UserData>* tracked_users_;
00139
00140 float m_pDepthHist[MAX_DEPTH];
00141 char m_strSampleName[ONI_MAX_STR];
00142
00143 unsigned int m_nTexMapX;
00144 unsigned int m_nTexMapY;
00145
00146 nite::UserTracker* m_pUserTracker;
00147 nite::UserId m_poseUser;
00148
00149 openni::RGB888Pixel* m_pTexMap_;
00150
00151 uint64_t m_poseTime_;
00152 unsigned int marker_id_;
00153 int poseTimeoutToExit_;
00154
00155 bool drawSkeleton_;
00156 bool drawCenterOfMass_;
00157 bool drawUserName_;
00158 bool drawBoundingBox_;
00159 bool drawBackground_;
00160 bool drawDepth_;
00161 bool drawFrames_;
00162
00163 int init_counter_color_image_;
00164 int init_counter_point_cloud_;
00165
00166 BodyTracker(const BodyTracker&);
00167 BodyTracker& operator=(BodyTracker&);
00168
00169 void init();
00170 void imageCallback(const sensor_msgs::ImageConstPtr& rgb_image_msg);
00171 void pointcloudCallback(const sensor_msgs::PointCloud2::ConstPtr& pointcloud);
00172 void updateUserState(const nite::UserData& user, uint64_t ts);
00173 void publishJoints(ros::NodeHandle& nh, tf::TransformBroadcaster& br, std::string joint_name,
00174 nite::SkeletonJoint joint, std::string tf_prefix, std::string rel_frame, int id);
00175 void publishTrackedUserMsg();
00176 void drawLine(const double r, const double g, const double b,
00177 const nite::Point3f& pose_start, const nite::Point3f& pose_end );
00178 void drawCircle(const double r, const double g, const double b,
00179 const nite::Point3f& pose);
00180 void drawSkeleton(nite::UserTracker* pUserTracker, const nite::UserData& userData);
00181 void drawUserName(const nite::UserData& user, cv::Mat& color_image, cv::Point& tag_coords);
00182 void drawFrames(const nite::UserData& user);
00183 void drawPointCloud();
00184 void drawLimb(nite::UserTracker* pUserTracker, const nite::SkeletonJoint& joint1, const nite::SkeletonJoint& joint2, int color);
00185 void calculateHistogram(float* pHistogram, int histogramSize, const openni::VideoFrameRef& depthFrame);
00186 void convertColorImageMsgToMat(const sensor_msgs::Image::ConstPtr& color_image_msg,
00187 cv_bridge::CvImageConstPtr& color_image_ptr, cv::Mat& color_image);
00188 unsigned long convertColorImageMessageToMat(const sensor_msgs::Image::ConstPtr& color_image_msg,
00189 cv_bridge::CvImageConstPtr& color_image_ptr, cv::Mat& color_image);
00190 geometry_msgs::Pose convertNiteJointToMsgs(nite::SkeletonJoint joint);
00191
00192 };
00193
00194 #endif // _NITE_USER_VIEWER_H_