Chapter 7. NiTE and Skeleton Tracking

In this chapter, we will cover:

  • Detecting a user's pose
  • Getting a user's skeleton joints and displaying their position in the depth map
  • Designing a simple pong game using skeleton tracking

Introduction

The most important feature of NiTE is recognizing a user's skeleton structure and giving developers the approximate position of each joint. In this chapter, we are going to cover this topic in the first two recipes. Then we will show you how to use this data to create a simple, pong-like game.

The nite::UserTracker object

We already talked about nite::UserTracker in Chapter 5, NiTE and User Tracking. In this chapter, we will introduce some of the other methods of this class that are going to be used.

A list of the most important methods of this class is as follows:

  • nite::UserTracker::startPoseDetection(): This method starts searching for a specific pose of a specific user. If you want to search for more than one pose for a user, you can simply call this method multiple times with different arguments.
  • nite::UserTracker::startSkeletonTracking(): This method starts the process of recognizing the position and orientation of the skeleton joints of a specific user.
  • nite::UserTracker::stopPoseDetection(): This method will stop searching for a specific pose for a specific user. You need to call this method once for each pose if you added multiple poses.
  • nite::UserTracker::stopSkeletonTracking(): This method will stop the processes of recognizing a user's skeleton and that of tracking him/her.

The nite::PoseData object

nite::PoseData is responsible for one of the user's current poses. In other words, a user can have more than one nite::PoseData object and each one will show the user's status about that pose.

nite::PoseData has a number of methods; some of them are listed as follows:

  • nite::PoseData::getType(): The returned value of this method is of the nite::PoseType type. nite::PoseType is an enum value that contains only two members, nite::POSE_PSI and nite::POSE_CROSSED_HANDS
  • nite::PoseData::isEntered(): This method's return value is a bool value that indicates if this is the first frame that this pose recognizes
  • nite::PoseData::isExited(): This method's return value is a bool type that indicates if this is the first frame in which the user left the pose
  • nite::PoseData::isHeld(): Just as with the preceding two methods, this method's return value is of the type bool and indicates whether a user is currently in this pose

The nite::Skeleton object

The nite::Skeleton object is responsible for giving you access to a list of all the skeleton joints (nite::SkeletonJoint) and lets you see the status of the user being tracked, lets you recognize the skeleton, and enables calibration. By using this object, which has only two methods, you can see if skeleton tracking is active and whether you can request more information about each joint.

  • nite::Skeleton::getJoint(): This returns the nite::SkeletonJoint object of the selected joint. This method accepts one argument that is of the type nite::JointType enum.
  • nite::Skeleton::getState(): The return value is of the type nite::SkeletonState enum; it shows the current state of a user's skeleton being tracked. The members of nite::SkeletonState are as follows:
    • nite::SKELETON_NONE: There is no skeleton data available or that has been requested
    • nite::SKELETON_CALIBRATING: This indicates that the skeleton is being prepared, but it's not ready yet
    • nite::SKELETON_TRACKED: The skeleton is available and can be read
    • nite::SKELETON_CALIBRATION_ERROR_NOT_IN_POSE: Usually, there is no need for a user to be in the PSI pose for calibration in the new version of NiTE; yet if it was needed, and NiTE found any reason to use this pose, but the user wasn't in the PSI pose, this is what the state of the nite::Skeleton::getState() method would be
    • nite::SKELETON_CALIBRATION_ERROR_HANDS: The calibration failed to find the hands
    • nite::SKELETON_CALIBRATION_ERROR_HEAD: The calibration failed to find head
    • nite::SKELETON_CALIBRATION_ERROR_LEGS: The calibration failed to find legs
    • nite::SKELETON_CALIBRATION_ERROR_TORSO: The calibration failed to find the torso

The nite::SkeletonJoint object

nite::SkeletonJoint gives you more information about a skeleton joint. Every recognized skeleton joint of a user has a nite::SkeletonJoint class to store its information. You can access each nite::SkeletonJoint object from the nite::Skeleton object. Here are some methods of this object:

  • nite::SkeletonJoint::getOrientation(): This method gives you a nite::Quaternion struct that shows the current orientation of a joint. The nite::Quaternion structure contains four float fields that can be used to find out the normal vector and radius of a rotation.
  • nite::SkeletonJoint::getOrientationConfidence(): The return value is of the float type and shows the confidence value of NiTE for returning the Quaternion orientation. This value is between 0 and 1.
  • nite::SkeletonJoint::getPosition(): This returns a nite::Point3fstruct value that contains three float fields showing the position of a joint in 3D space.
  • nite::SkeletonJoint::getPositionConfidence(): This method's return value is of the float type and shows the confidence value of NiTE for returning the position point. This value is between 0 and 1.
  • nite::SkeletonJoint::getType(): This method's return value is of the type nite::JointType enum and shows the types of this joint. nite::JointType enum contains the following members:
    • nite::JOINT_HEAD
    • nite::JOINT_NECK
    • nite::JOINT_LEFT_SHOULDER
    • nite::JOINT_RIGHT_SHOULDER
    • nite::JOINT_LEFT_ELBOW
    • nite::JOINT_RIGHT_ELBOW
    • nite::JOINT_LEFT_HAND
    • nite::JOINT_RIGHT_HAND
    • nite::JOINT_TORSO
    • nite::JOINT_LEFT_HIP
    • nite::JOINT_RIGHT_HIP
    • nite::JOINT_LEFT_KNEE
    • nite::JOINT_RIGHT_KNEE
    • nite::JOINT_LEFT_FOOT
    • nite::JOINT_RIGHT_FOOT

The nite::UserData object

nite::UserData is a class representing a user. In another words, nite::UserTrackerFrameRef gives you a nite::UserData object for each user it has recognized.

We already introduced some of the nite::UserData object's methods in Chapter 5, NiTE and User Tracking. Here we are going to show you some other methods related to the subject of this recipe as follows:

  • nite::UserData::getPose(): This method gives you access to the related nite::PoseData object of the requested pose of a user. The only argument of this method is a nite::PoseType enum value that lets you select your desired pose to give you more information about it.
  • nite::UserData::getSkeleton(): This method gives you the nite::Skeleton object of the selected user. In the next section, we will tell you what a nite::Skeleton object is and expound on its important methods.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.37.12