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"};
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);
179 0, 0, 0.5 * BODY_LENGTH + HEAD_RADIUS, 0, 0, 0));
185 mrpt::make_aligned_shared<CCylinder>(
186 BODY_RADIUS, BODY_RADIUS, BODY_LENGTH);
187 part->setColor(1, 1, 1, ALPHA_CH);
195 mrpt::make_aligned_shared<CCylinder>(
196 ARM_RADIUS, ARM_RADIUS, ARM_LENGTH);
197 part->setColor(1, 1, 1, ALPHA_CH);
199 -BODY_RADIUS, 0, 0.5 * BODY_LENGTH - ARM_RADIUS, 0,
206 mrpt::make_aligned_shared<CCylinder>(
207 ARM_RADIUS, ARM_RADIUS, ARM_LENGTH);
208 part->setColor(1, 1, 1, ALPHA_CH);
210 -BODY_RADIUS - ARM_LENGTH + ARM_RADIUS, 0,
211 0.5 * BODY_LENGTH - ARM_RADIUS, 0, 0, 0));
217 mrpt::make_aligned_shared<CCylinder>(
218 ARM_RADIUS, ARM_RADIUS, ARM_LENGTH);
219 part->setColor(1, 1, 1, ALPHA_CH);
221 BODY_RADIUS, 0, 0.5 * BODY_LENGTH - ARM_RADIUS, 0,
228 mrpt::make_aligned_shared<CCylinder>(
229 ARM_RADIUS, ARM_RADIUS, ARM_LENGTH);
230 part->setColor(1, 1, 1, ALPHA_CH);
232 BODY_RADIUS + ARM_LENGTH - ARM_RADIUS, 0,
233 0.5 * BODY_LENGTH - ARM_RADIUS, 0, 0, 0));
239 mrpt::make_aligned_shared<CCylinder>(
240 LEG_RADIUS, LEG_RADIUS, LEG_LENGTH);
241 part->setColor(1, 1, 1, ALPHA_CH);
243 -BODY_RADIUS + LEG_RADIUS, 0,
244 -(0.5 * BODY_LENGTH + LEG_LENGTH), 0, 0, 0));
250 mrpt::make_aligned_shared<CCylinder>(
251 LEG_RADIUS, LEG_RADIUS, LEG_LENGTH);
252 part->setColor(1, 1, 1, ALPHA_CH);
254 BODY_RADIUS - LEG_RADIUS, 0,
255 -(0.5 * BODY_LENGTH + LEG_LENGTH), 0, 0, 0));
258 scene->insert(dummy);
264 scene->getByName(
"dummy"));
265 dummy->setVisibility(
true);
271 scene->getByName(
"body"));
289 s->setColor(1, 0, 0);
290 s->setRadius(i == 0 ? 0.07 : 0.03);
293 m_win->unlockAccess3DScene();
294 m_win->forceRepaint();
313 m_win = mrpt::make_aligned_shared<mrpt::gui::CDisplayWindow3D>(
318 mrpt::make_aligned_shared<CGridPlaneXZ>(-3, 3, 0, 5, -1.5));
321 m_win->setCameraElevationDeg(-90);
322 m_win->setCameraAzimuthDeg(90);
323 m_win->setCameraZoom(4);
324 m_win->setCameraPointingToPoint(0, 0, 0);
328 mrpt::make_aligned_shared<CSetOfObjects>();
329 body->setName(
"body");
332 CSphere::Ptr sph = mrpt::make_aligned_shared<CSphere>(0.03f);
333 sph->setColor(0, 1, 0);
340 lines->setName(
"lines");
341 lines->setColor(0, 0, 1);
345 m_win->unlockAccess3DScene();
353 m_win->clearTextMessages();
355 scene->getByName(
"dummy"));
356 if (dummy) dummy->setVisibility(
false);
362 scene->getByName(
"body"));
382 j = obs->left_shoulder;
401 j = obs->right_shoulder;
404 j = obs->right_elbow;
423 j.
x * 1e-3, j.
y * 1e-3, j.
z * 1e-3, 0, 0, 0));
427 s->setRadius(i == 0 ? 0.07 : 0.03);
432 body->getByName(
"lines"));
446 s0->getPoseX(), s0->getPoseY(), s0->getPoseZ(),
447 s1->getPoseX(), s1->getPoseY(), s1->getPoseZ());
450 m_win->unlockAccess3DScene();
451 m_win->forceRepaint();
461 #if MRPT_HAS_OPENNI2 && MRPT_HAS_NITE2 464 std::this_thread::sleep_for(200ms);
470 nite::UserTrackerFrameRef userTrackerFrame;
473 if (niteRc != nite::STATUS_OK)
475 printf(
" [Skeleton tracker] Get next frame failed\n");
480 const nite::Array<nite::UserData>& users = userTrackerFrame.getUsers();
484 const nite::UserData& user = users[i];
487 skl_states[user.getId()] = user.getSkeleton().getState();
492 cout <<
" [Skeleton tracker] New user found" << endl;
494 else if (user.getSkeleton().getState() == nite::SKELETON_TRACKED)
496 cout <<
" [Skeleton tracker] User " << user.getId() <<
" tracked" 499 mrpt::make_aligned_shared<CObservationSkeleton>();
502 const uint64_t nowUI = userTrackerFrame.getTimestamp();
514 const auto AtDO = std::chrono::microseconds(AtUI);
556 cout <<
" [Skeleton tracker] Looking for user..." << endl;
564 cout <<
" [Skeleton tracker] No user found after 2000 attempts ..." 566 nite::NiTE::shutdown();
570 "MRPT has been compiled with 'BUILD_OPENNI2'=OFF or " 571 "'MRPT_HAS_NITE2'=OFF, so this class cannot be used.");
580 #if MRPT_HAS_OPENNI2 && MRPT_HAS_NITE2 583 nite::NiTE::initialize();
586 if (niteRc != nite::STATUS_OK)
588 printf(
"Couldn't create user tracker\n");
593 printf(
"Sucessfully created user tracker \n");
595 "Start moving around to get detected...\n(PSI pose may be required " 596 "for skeleton calibration, depending on the configuration)\n");
619 "MRPT has been compiled with 'BUILD_OPENNI2'=OFF OR " 620 "'MRPT_HAS_NITE2'=OFF, so this class cannot be used.");
632 configSource.
read_float(iniSection,
"pose_x", 0,
false),
633 configSource.
read_float(iniSection,
"pose_y", 0,
false),
634 configSource.
read_float(iniSection,
"pose_z", 0,
false),
643 cout <<
"---------------------------" << endl;
644 cout <<
"Skeleton Tracker parameters: " << endl;
645 cout <<
"---------------------------" << endl;
648 cout <<
"---------------------------" << endl << endl;
void doProcess()
This method will be invoked at a minimum rate of "process_rate" (Hz)
void appendObservation(const mrpt::serialization::CSerializable::Ptr &obj)
Like appendObservations() but for just one observation.
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...
#define THROW_EXCEPTION(msg)
virtual ~CSkeletonTracker()
Destructor.
mrpt::system::TTimeStamp m_timeStartTT
std::string m_sensorLabel
See CGenericSensor.
double DEG2RAD(const double x)
Degrees to radians.
void loadConfig_sensorSpecific(const mrpt::config::CConfigFileBase &configSource, const std::string &iniSection)
See the class documentation at the top for expected parameters.
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.
float read_float(const std::string §ion, const std::string &name, float defaultValue, bool failIfNotFound=false) const
int m_nUsers
Number of detected users.
mrpt::poses::CPose3D m_sensorPose
Sensor pose.
void processPreview(const mrpt::obs::CObservationSkeleton::Ptr &obs)
Displays real-time info for the captured skeleton.
CRenderizable & setColor(const mrpt::img::TColorf &c)
Changes the default object color.
#define ASSERT_(f)
Defines an assertion mechanism.
mrpt::Clock::time_point TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
This class allows loading and storing values and vectors of different types from a configuration text...
A class for grabbing mrpt::obs::CObservationSkeleton from a PrimeSense camera.
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.
enum Status { eInsideTag=0, eOutsideTag } Status
void processPreviewNone()
GLsizei const GLchar ** string
CSkeletonTracker()
Constructor.
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...
unsigned __int64 uint64_t
bool m_showPreview
Preview window management.
bool read_bool(const std::string §ion, const std::string &name, bool defaultValue, bool failIfNotFound=false) const
A solid or wire-frame sphere.
A RGB color - floats in the range [0,1].
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.
CRenderizable & setPose(const mrpt::poses::CPose3D &o)
Set the 3D pose from a mrpt::poses::CPose3D object (return a ref to this)
std::string std::string to_string(T v)
Just like std::to_string(), but with an overloaded version for std::string arguments.
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
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.