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 #include "cob_people_detection/SceneDrawer.h"
00027
00028 extern xn::UserGenerator g_UserGenerator;
00029 extern xn::DepthGenerator g_DepthGenerator;
00030
00031 #define MAX_DEPTH 10000
00032 float g_pDepthHist[MAX_DEPTH];
00033 unsigned int getClosestPowerOfTwo(unsigned int n)
00034 {
00035 unsigned int m = 2;
00036 while (m < n)
00037 m <<= 1;
00038
00039 return m;
00040 }
00041
00042 XnFloat Colors[][3] =
00043 {
00044 { 0, 1, 1 },
00045 { 0, 0, 1 },
00046 { 0, 1, 0 },
00047 { 1, 1, 0 },
00048 { 1, 0, 0 },
00049 { 1, .5, 0 },
00050 { .5, 1, 0 },
00051 { 0, .5, 1 },
00052 { .5, 0, 1 },
00053 { 1, 1, .5 },
00054 { 1, 1, 1 } };
00055 XnUInt32 nColors = 10;
00056
00057 void DrawLimb(XnUserID player, XnSkeletonJoint eJoint1, XnSkeletonJoint eJoint2)
00058 {
00059 if (!g_UserGenerator.GetSkeletonCap().IsTracking(player))
00060 {
00061 printf("not tracked!\n");
00062 return;
00063 }
00064
00065 XnSkeletonJointPosition joint1, joint2;
00066 g_UserGenerator.GetSkeletonCap().GetSkeletonJointPosition(player, eJoint1, joint1);
00067 g_UserGenerator.GetSkeletonCap().GetSkeletonJointPosition(player, eJoint2, joint2);
00068
00069 if (joint1.fConfidence < 0.5 || joint2.fConfidence < 0.5)
00070 {
00071 return;
00072 }
00073
00074 XnPoint3D pt[2];
00075 pt[0] = joint1.position;
00076 pt[1] = joint2.position;
00077
00078 g_DepthGenerator.ConvertRealWorldToProjective(2, pt, pt);
00079 }
00080
00081 void PublishPeopleImage(const xn::DepthMetaData& dmd, const xn::SceneMetaData& smd, image_transport::Publisher& pub)
00082 {
00083 const XnDepthPixel* pDepth = dmd.Data();
00084 const XnLabel* pLabels = smd.Data();
00085 unsigned int nValue = 0;
00086 XnUInt16 g_nXRes = dmd.XRes();
00087 XnUInt16 g_nYRes = dmd.YRes();
00088 cv::Mat peopleSegmentation(g_nYRes, g_nXRes, CV_8UC3);
00089
00090
00091 for (unsigned int nY = 0; nY < g_nYRes; nY++)
00092 {
00093 uchar* pDestImage = peopleSegmentation.ptr(nY);
00094 for (unsigned int nX = 0; nX < g_nXRes; nX++)
00095 {
00096
00097 pDestImage[0] = 0;
00098 pDestImage[1] = 0;
00099 pDestImage[2] = 0;
00100 if (*pLabels != 0)
00101 {
00102 nValue = *pDepth;
00103 XnLabel label = *pLabels;
00104 XnUInt32 nColorID = label % nColors;
00105
00106 if (nValue != 0)
00107 {
00108 pDestImage[0] = 255 * Colors[nColorID][0];
00109 pDestImage[1] = 255 * Colors[nColorID][1];
00110 pDestImage[2] = 255 * Colors[nColorID][2];
00111 }
00112 }
00113
00114 pDepth++;
00115 pLabels++;
00116 pDestImage += 3;
00117 }
00118 }
00119
00120
00121
00122
00123 try
00124 {
00125 IplImage img = (IplImage)peopleSegmentation;
00126 sensor_msgs::ImagePtr msg = (sensor_msgs::CvBridge::cvToImgMsg(&img, "bgr8"));
00127 msg->header.stamp = ros::Time::now();
00128 pub.publish(msg);
00129 } catch (sensor_msgs::CvBridgeException error)
00130 {
00131 ROS_ERROR("[openni_tracker] Could not convert IplImage to ROS message");
00132 }
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154 }