34 #define skl_states (static_cast<nite::SkeletonState*>(m_skeletons_ptr)) 35 #define user_tracker (static_cast<nite::UserTracker*>(m_userTracker_ptr)) 37 #define FILL_JOINT_DATA(_J1, _J2) \ 38 obs->_J1.x = user.getSkeleton().getJoint(_J2).getPosition().x; \ 39 obs->_J1.y = user.getSkeleton().getJoint(_J2).getPosition().y; \ 40 obs->_J1.z = user.getSkeleton().getJoint(_J2).getPosition().z; \ 41 obs->_J1.conf = user.getSkeleton().getJoint(_J2).getPositionConfidence(); 45 #pragma comment(lib, "NiTE2.lib") 49 "head",
"neck",
"torso",
"left_shoulder",
"left_elbow",
50 "left_hand",
"left_hip",
"left_knee",
"left_foot",
"right_shoulder",
51 "right_elbow",
"right_hand",
"right_hip",
"right_knee",
"right_foot"};
56 CSkeletonTracker::CSkeletonTracker()
57 : m_skeletons_ptr(nullptr),
58 m_userTracker_ptr(nullptr),
68 #if MRPT_HAS_OPENNI2 && MRPT_HAS_NITE2 79 "MRPT has been compiled with 'BUILD_OPENNI2'=OFF or 'BUILD_NITE2'=OFF, " 80 "so this class cannot be used.");
89 #if MRPT_HAS_OPENNI2 && MRPT_HAS_NITE2 90 nite::NiTE::shutdown();
112 m_win = mrpt::make_aligned_shared<mrpt::gui::CDisplayWindow3D>(
117 mrpt::make_aligned_shared<CGridPlaneXZ>(-3, 3, 0, 5, -1.5));
120 m_win->setCameraElevationDeg(-90);
121 m_win->setCameraAzimuthDeg(90);
122 m_win->setCameraZoom(4);
123 m_win->setCameraPointingToPoint(0, 0, 0);
127 mrpt::make_aligned_shared<CSetOfObjects>();
128 body->setName(
"body");
131 CSphere::Ptr sph = mrpt::make_aligned_shared<CSphere>(0.03f);
132 sph->setColor(0, 1, 0);
139 lines->setName(
"lines");
140 lines->setColor(0, 0, 1);
144 m_win->unlockAccess3DScene();
151 m_win->addTextMessage(
152 0.35, 0.9,
"Please, adopt this position",
TColorf(1, 1, 1),
157 if (!scene->getByName(
"dummy"))
159 const double SCALE = 0.8;
160 const double BODY_RADIUS = 0.22 * SCALE;
161 const double BODY_LENGTH = 0.8 * SCALE;
162 const double ARM_RADIUS = 0.05 * SCALE;
163 const double ARM_LENGTH = 0.4 * SCALE;
164 const double LEG_RADIUS = 0.1 * SCALE;
165 const double LEG_LENGTH = 0.8 * SCALE;
166 const double HEAD_RADIUS = 0.15 * SCALE;
167 const double ALPHA_CH = 0.8;
170 mrpt::make_aligned_shared<CSetOfObjects>();
171 dummy->setName(
"dummy");
176 mrpt::make_aligned_shared<CSphere>(HEAD_RADIUS);
177 part->setColor(1, 1, 1, ALPHA_CH);
180 0, 0, 0.5 * BODY_LENGTH + HEAD_RADIUS, 0, 0,
187 mrpt::make_aligned_shared<CCylinder>(
188 BODY_RADIUS, BODY_RADIUS, BODY_LENGTH);
189 part->setColor(1, 1, 1, ALPHA_CH);
197 mrpt::make_aligned_shared<CCylinder>(
198 ARM_RADIUS, ARM_RADIUS, ARM_LENGTH);
199 part->setColor(1, 1, 1, ALPHA_CH);
202 -BODY_RADIUS, 0, 0.5 * BODY_LENGTH - ARM_RADIUS,
209 mrpt::make_aligned_shared<CCylinder>(
210 ARM_RADIUS, ARM_RADIUS, ARM_LENGTH);
211 part->setColor(1, 1, 1, ALPHA_CH);
214 -BODY_RADIUS - ARM_LENGTH + ARM_RADIUS, 0,
215 0.5 * BODY_LENGTH - ARM_RADIUS, 0, 0, 0));
221 mrpt::make_aligned_shared<CCylinder>(
222 ARM_RADIUS, ARM_RADIUS, ARM_LENGTH);
223 part->setColor(1, 1, 1, ALPHA_CH);
226 BODY_RADIUS, 0, 0.5 * BODY_LENGTH - ARM_RADIUS,
233 mrpt::make_aligned_shared<CCylinder>(
234 ARM_RADIUS, ARM_RADIUS, ARM_LENGTH);
235 part->setColor(1, 1, 1, ALPHA_CH);
238 BODY_RADIUS + ARM_LENGTH - ARM_RADIUS, 0,
239 0.5 * BODY_LENGTH - ARM_RADIUS, 0, 0, 0));
245 mrpt::make_aligned_shared<CCylinder>(
246 LEG_RADIUS, LEG_RADIUS, LEG_LENGTH);
247 part->setColor(1, 1, 1, ALPHA_CH);
250 -BODY_RADIUS + LEG_RADIUS, 0,
251 -(0.5 * BODY_LENGTH + LEG_LENGTH), 0, 0, 0));
257 mrpt::make_aligned_shared<CCylinder>(
258 LEG_RADIUS, LEG_RADIUS, LEG_LENGTH);
259 part->setColor(1, 1, 1, ALPHA_CH);
262 BODY_RADIUS - LEG_RADIUS, 0,
263 -(0.5 * BODY_LENGTH + LEG_LENGTH), 0, 0, 0));
266 scene->insert(dummy);
272 scene->getByName(
"dummy"));
279 scene->getByName(
"body"));
297 s->setColor(1, 0, 0);
298 s->setRadius(i == 0 ? 0.07 : 0.03);
301 m_win->unlockAccess3DScene();
302 m_win->forceRepaint();
321 m_win = mrpt::make_aligned_shared<mrpt::gui::CDisplayWindow3D>(
326 mrpt::make_aligned_shared<CGridPlaneXZ>(-3, 3, 0, 5, -1.5));
329 m_win->setCameraElevationDeg(-90);
330 m_win->setCameraAzimuthDeg(90);
331 m_win->setCameraZoom(4);
332 m_win->setCameraPointingToPoint(0, 0, 0);
336 mrpt::make_aligned_shared<CSetOfObjects>();
337 body->setName(
"body");
340 CSphere::Ptr sph = mrpt::make_aligned_shared<CSphere>(0.03f);
341 sph->setColor(0, 1, 0);
348 lines->setName(
"lines");
349 lines->setColor(0, 0, 1);
353 m_win->unlockAccess3DScene();
361 m_win->clearTextMessages();
363 scene->getByName(
"dummy"));
370 scene->getByName(
"body"));
390 j = obs->left_shoulder;
409 j = obs->right_shoulder;
412 j = obs->right_elbow;
432 j.
x * 1e-3, j.
y * 1e-3, j.
z * 1e-3, 0, 0, 0));
436 s->setRadius(i == 0 ? 0.07 : 0.03);
441 body->getByName(
"lines"));
455 s0->getPoseX(), s0->getPoseY(), s0->getPoseZ(),
456 s1->getPoseX(), s1->getPoseY(), s1->getPoseZ());
459 m_win->unlockAccess3DScene();
460 m_win->forceRepaint();
470 #if MRPT_HAS_OPENNI2 && MRPT_HAS_NITE2 473 std::this_thread::sleep_for(200ms);
479 nite::UserTrackerFrameRef userTrackerFrame;
482 if (niteRc != nite::STATUS_OK)
484 printf(
" [Skeleton tracker] Get next frame failed\n");
489 const nite::Array<nite::UserData>& users = userTrackerFrame.getUsers();
493 const nite::UserData& user = users[i];
496 skl_states[user.getId()] = user.getSkeleton().getState();
501 cout <<
" [Skeleton tracker] New user found" << endl;
503 else if (user.getSkeleton().getState() == nite::SKELETON_TRACKED)
505 cout <<
" [Skeleton tracker] User " << user.getId() <<
" tracked" 508 mrpt::make_aligned_shared<CObservationSkeleton>();
511 const uint64_t nowUI = userTrackerFrame.getTimestamp();
564 cout <<
" [Skeleton tracker] Looking for user..." << endl;
572 cout <<
" [Skeleton tracker] No user found after 2000 attempts ..." 574 nite::NiTE::shutdown();
578 "MRPT has been compiled with 'BUILD_OPENNI2'=OFF or " 579 "'MRPT_HAS_NITE2'=OFF, so this class cannot be used.");
588 #if MRPT_HAS_OPENNI2 && MRPT_HAS_NITE2 591 nite::NiTE::initialize();
594 if (niteRc != nite::STATUS_OK)
596 printf(
"Couldn't create user tracker\n");
601 printf(
"Sucessfully created user tracker \n");
603 "Start moving around to get detected...\n(PSI pose may be required " 604 "for skeleton calibration, depending on the configuration)\n");
627 "MRPT has been compiled with 'BUILD_OPENNI2'=OFF OR " 628 "'MRPT_HAS_NITE2'=OFF, so this class cannot be used.");
640 configSource.
read_float(iniSection,
"pose_x", 0,
false),
641 configSource.
read_float(iniSection,
"pose_y", 0,
false),
642 configSource.
read_float(iniSection,
"pose_z", 0,
false),
651 cout <<
"---------------------------" << endl;
652 cout <<
"Skeleton Tracker parameters: " << endl;
653 cout <<
"---------------------------" << endl;
656 cout <<
"---------------------------" << endl << endl;
uint64_t TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
bool read_bool(const std::string §ion, const std::string &name, bool defaultValue, bool failIfNotFound=false) const
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
void doProcess()
This method will be invoked at a minimum rate of "process_rate" (Hz)
void * m_skeletons_ptr
Opaque pointers to specific NITE data.
A set of object, which are referenced to the coordinates framework established in this object...
virtual ~CSkeletonTracker()
Destructor.
float read_float(const std::string §ion, const std::string &name, float defaultValue, bool failIfNotFound=false) const
mrpt::system::TTimeStamp m_timeStartTT
void loadConfig_sensorSpecific(const mrpt::utils::CConfigFileBase &configSource, const std::string &iniSection)
See the class documentation at the top for expected parameters.
std::string m_sensorLabel
See CGenericSensor.
#define THROW_EXCEPTION(msg)
unsigned int m_toutCounter
Timeout counter (for internal use only)
mrpt::system::TTimeStamp now()
A shortcut for system::getCurrentTime.
Contains classes for various device interfaces.
std::shared_ptr< CObservationSkeleton > Ptr
CRenderizable & setColor(const mrpt::utils::TColorf &c)
Changes the default object color.
int m_nUsers
Number of detected users.
This class allows loading and storing values and vectors of different types from a configuration text...
mrpt::poses::CPose3D m_sensorPose
Sensor pose.
void processPreview(const mrpt::obs::CObservationSkeleton::Ptr &obs)
Displays real-time info for the captured skeleton.
A class for grabbing mrpt::obs::CObservationSkeleton from a PrimeSense camera.
std::shared_ptr< CCylinder > Ptr
std::shared_ptr< CSetOfObjects > Ptr
This namespace contains representation of robot actions and observations.
void initialize()
Connects to the PrimeSense camera and prepares it to get skeleton data.
double conf
Confidence value [0...1].
std::vector< std::pair< JOINT, JOINT > > m_linesToPlot
Lines between joints.
void processPreviewNone()
GLsizei const GLchar ** string
A class used to store a 3D point.
#define IMPLEMENTS_GENERIC_SENSOR(class_name, NameSpace)
This must be inserted in all CGenericSensor classes implementation files:
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
void appendObservation(const mrpt::utils::CSerializable::Ptr &obj)
Like appendObservations() but for just one observation.
unsigned __int64 uint64_t
bool m_showPreview
Preview window management.
void setVisibility(bool visible=true)
Set object visibility (default=true)
A solid or wire-frame sphere.
std::shared_ptr< COpenGLScene > Ptr
void setFromValues(const double x0, const double y0, const double z0, const double yaw=0, const double pitch=0, const double roll=0)
Set the pose from a 3D position (meters) and yaw/pitch/roll angles (radians) - This method recomputes...
Lightweight 3D pose (three spatial coordinates, plus three angular coordinates).
The namespace for 3D scene representation and rendering.
A RGB color - floats in the range [0,1].
std::shared_ptr< CSetOfLines > Ptr
CRenderizable & setPose(const mrpt::poses::CPose3D &o)
Set the 3D pose from a mrpt::poses::CPose3D object (return a ref to this)
mrpt::system::TTimeStamp secondsToTimestamp(const double nSeconds)
Transform a time interval (in seconds) into TTimeStamp (e.g.
A generic joint for the skeleton observation.
A set of independent lines (or segments), one line with its own start and end positions (X...
uint32_t m_timeStartUI
Timestamp management.
renders glyphs as filled polygons
std::shared_ptr< CSphere > Ptr
mrpt::gui::CDisplayWindow3D::Ptr m_win
#define FILL_JOINT_DATA(_J1, _J2)
std::vector< double > m_joint_theta
Joint angles when no skeleton has been detected.