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"};
61 #if MRPT_HAS_OPENNI2 && MRPT_HAS_NITE2 72 "MRPT has been compiled with 'BUILD_OPENNI2'=OFF or 'BUILD_NITE2'=OFF, " 73 "so this class cannot be used.");
82 #if MRPT_HAS_OPENNI2 && MRPT_HAS_NITE2 83 nite::NiTE::shutdown();
108 scene->insert(std::make_shared<CGridPlaneXZ>(-3, 3, 0, 5, -1.5));
111 m_win->setCameraElevationDeg(-90);
112 m_win->setCameraAzimuthDeg(90);
113 m_win->setCameraZoom(4);
114 m_win->setCameraPointingToPoint(0, 0, 0);
118 body->setName(
"body");
122 sph->setColor(0, 1, 0);
123 sph->setName(jointName);
129 lines->setName(
"lines");
130 lines->setColor(0, 0, 1);
134 m_win->unlockAccess3DScene();
141 m_win->addTextMessage(
142 0.35, 0.9,
"Please, adopt this position",
TColorf(1, 1, 1),
147 if (!scene->getByName(
"dummy"))
149 const double SCALE = 0.8;
150 const double BODY_RADIUS = 0.22 * SCALE;
151 const double BODY_LENGTH = 0.8 * SCALE;
152 const double ARM_RADIUS = 0.05 * SCALE;
153 const double ARM_LENGTH = 0.4 * SCALE;
154 const double LEG_RADIUS = 0.1 * SCALE;
155 const double LEG_LENGTH = 0.8 * SCALE;
156 const double HEAD_RADIUS = 0.15 * SCALE;
157 const double ALPHA_CH = 0.8;
160 std::make_shared<CSetOfObjects>();
161 dummy->setName(
"dummy");
166 std::make_shared<CSphere>(HEAD_RADIUS);
167 part->setColor(1, 1, 1, ALPHA_CH);
169 0, 0, 0.5 * BODY_LENGTH + HEAD_RADIUS, 0, 0, 0));
175 BODY_RADIUS, BODY_RADIUS, BODY_LENGTH);
176 part->setColor(1, 1, 1, ALPHA_CH);
184 ARM_RADIUS, ARM_RADIUS, ARM_LENGTH);
185 part->setColor(1, 1, 1, ALPHA_CH);
187 -BODY_RADIUS, 0, 0.5 * BODY_LENGTH - ARM_RADIUS, 0,
194 ARM_RADIUS, ARM_RADIUS, ARM_LENGTH);
195 part->setColor(1, 1, 1, ALPHA_CH);
197 -BODY_RADIUS - ARM_LENGTH + ARM_RADIUS, 0,
198 0.5 * BODY_LENGTH - ARM_RADIUS, 0, 0, 0));
204 ARM_RADIUS, ARM_RADIUS, ARM_LENGTH);
205 part->setColor(1, 1, 1, ALPHA_CH);
207 BODY_RADIUS, 0, 0.5 * BODY_LENGTH - ARM_RADIUS, 0,
214 ARM_RADIUS, ARM_RADIUS, ARM_LENGTH);
215 part->setColor(1, 1, 1, ALPHA_CH);
217 BODY_RADIUS + ARM_LENGTH - ARM_RADIUS, 0,
218 0.5 * BODY_LENGTH - ARM_RADIUS, 0, 0, 0));
224 LEG_RADIUS, LEG_RADIUS, LEG_LENGTH);
225 part->setColor(1, 1, 1, ALPHA_CH);
227 -BODY_RADIUS + LEG_RADIUS, 0,
228 -(0.5 * BODY_LENGTH + LEG_LENGTH), 0, 0, 0));
234 LEG_RADIUS, LEG_RADIUS, LEG_LENGTH);
235 part->setColor(1, 1, 1, ALPHA_CH);
237 BODY_RADIUS - LEG_RADIUS, 0,
238 -(0.5 * BODY_LENGTH + LEG_LENGTH), 0, 0, 0));
241 scene->insert(dummy);
247 scene->getByName(
"dummy"));
248 dummy->setVisibility(
true);
254 scene->getByName(
"body"));
272 s->setColor(1, 0, 0);
273 s->setRadius(i == 0 ? 0.07 : 0.03);
276 m_win->unlockAccess3DScene();
277 m_win->forceRepaint();
299 scene->insert(std::make_shared<CGridPlaneXZ>(-3, 3, 0, 5, -1.5));
302 m_win->setCameraElevationDeg(-90);
303 m_win->setCameraAzimuthDeg(90);
304 m_win->setCameraZoom(4);
305 m_win->setCameraPointingToPoint(0, 0, 0);
309 body->setName(
"body");
313 sph->setColor(0, 1, 0);
314 sph->setName(jointName);
320 lines->setName(
"lines");
321 lines->setColor(0, 0, 1);
325 m_win->unlockAccess3DScene();
333 m_win->clearTextMessages();
335 scene->getByName(
"dummy"));
336 if (dummy) dummy->setVisibility(
false);
342 scene->getByName(
"body"));
362 j = obs->left_shoulder;
381 j = obs->right_shoulder;
384 j = obs->right_elbow;
403 j.
x * 1e-3, j.
y * 1e-3, j.
z * 1e-3, 0, 0, 0));
407 s->setRadius(i == 0 ? 0.07 : 0.03);
412 body->getByName(
"lines"));
426 s0->getPoseX(), s0->getPoseY(), s0->getPoseZ(),
427 s1->getPoseX(), s1->getPoseY(), s1->getPoseZ());
430 m_win->unlockAccess3DScene();
431 m_win->forceRepaint();
441 #if MRPT_HAS_OPENNI2 && MRPT_HAS_NITE2 444 std::this_thread::sleep_for(200ms);
450 nite::UserTrackerFrameRef userTrackerFrame;
453 if (niteRc != nite::STATUS_OK)
455 printf(
" [Skeleton tracker] Get next frame failed\n");
460 const nite::Array<nite::UserData>& users = userTrackerFrame.getUsers();
464 const nite::UserData& user = users[i];
467 skl_states[user.getId()] = user.getSkeleton().getState();
472 cout <<
" [Skeleton tracker] New user found" << endl;
474 else if (user.getSkeleton().getState() == nite::SKELETON_TRACKED)
476 cout <<
" [Skeleton tracker] User " << user.getId() <<
" tracked" 479 std::make_shared<CObservationSkeleton>();
482 const uint64_t nowUI = userTrackerFrame.getTimestamp();
494 const auto AtDO = std::chrono::microseconds(AtUI);
536 cout <<
" [Skeleton tracker] Looking for user..." << endl;
544 cout <<
" [Skeleton tracker] No user found after 2000 attempts ..." 546 nite::NiTE::shutdown();
550 "MRPT has been compiled with 'BUILD_OPENNI2'=OFF or " 551 "'MRPT_HAS_NITE2'=OFF, so this class cannot be used.");
560 #if MRPT_HAS_OPENNI2 && MRPT_HAS_NITE2 563 nite::NiTE::initialize();
566 if (niteRc != nite::STATUS_OK)
568 printf(
"Couldn't create user tracker\n");
573 printf(
"Sucessfully created user tracker \n");
575 "Start moving around to get detected...\n(PSI pose may be required " 576 "for skeleton calibration, depending on the configuration)\n");
599 "MRPT has been compiled with 'BUILD_OPENNI2'=OFF OR " 600 "'MRPT_HAS_NITE2'=OFF, so this class cannot be used.");
612 configSource.
read_float(iniSection,
"pose_x", 0,
false),
613 configSource.
read_float(iniSection,
"pose_y", 0,
false),
614 configSource.
read_float(iniSection,
"pose_z", 0,
false),
623 cout <<
"---------------------------" << endl;
624 cout <<
"Skeleton Tracker parameters: " << endl;
625 cout <<
"---------------------------" << endl;
628 cout <<
"---------------------------" << endl << endl;
void appendObservation(const mrpt::serialization::CSerializable::Ptr &obj)
Like appendObservations() but for just one observation.
void initialize() override
Connects to the PrimeSense camera and prepares it to get skeleton data.
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)
mrpt::system::TTimeStamp m_timeStartTT
std::string m_sensorLabel
See CGenericSensor.
double DEG2RAD(const double x)
Degrees to radians.
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
static CDisplayWindow3D::Ptr Create(const std::string &windowCaption, unsigned int initialWindowWidth=400, unsigned int initialWindowHeight=300)
Class factory returning a smart pointer.
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...
~CSkeletonTracker() override
Destructor.
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.
void loadConfig_sensorSpecific(const mrpt::config::CConfigFileBase &configSource, const std::string &iniSection) override
See the class documentation at the top for expected parameters.
This namespace contains representation of robot actions and observations.
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
void doProcess() override
This method will be invoked at a minimum rate of "process_rate" (Hz)
#define FILL_JOINT_DATA(_J1, _J2)
std::vector< double > m_joint_theta
Joint angles when no skeleton has been detected.