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);
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);
271 std::dynamic_pointer_cast<CSetOfObjects>(
272 scene->getByName(
"dummy"));
273 dummy->setVisibility(
true);
278 std::dynamic_pointer_cast<CSetOfObjects>(
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"));
364 if (dummy) dummy->setVisibility(
false);
369 std::dynamic_pointer_cast<CSetOfObjects>(
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;