Exemple #1
0
/*
 *	Function:	getPosition
 *
 *	Returns the Position (enum defined in monitor.h) of the specified user.
 *	Positions are assigned based on joint locations and defined tolerances.
 *	Sets the location of the hospital bed if it has not yet been set and the patient
 *	is lying down.
 *
 *	Parameters:
 *		XnUserID	user	-	The id for the user whose position to get
 *
 *	Return:
 *		The Position of the user
 */
Position KinectMonitor::getPosition(XnUserID user) {
	XnSkeletonJointPosition headPos, torsoPos, leftPos, rightPos;
	double head, torso, center, left, right;
	Position position = UNKNOWN;
	SkeletonCapability skeleton = userGenerator.GetSkeletonCap();
	
	// Get Joint positions for the specified joint locations
	// Joints are XN_SKEL_<option> where <option> is:
	// HEAD, NECK, TORSO, WAIST, LEFT_COLLAR, LEFT_SHOULDER, LEFT_ELBOW, LEFT_WRIST, LEFT_HAND
	// LEFT_FINGERTIP, RIGHT_COLLAR, RIGHT_SHOULDER, RIGHT_ELBOW, RIGHT_WRIST, RIGHT_HAND,
	// RIGHT_FINGERTIP, LEFT_HIP, LEFT_KNEE, LEFT_ANKLE, LEFT_FOOT, RIGHT_HIP, RIGHT_KNEE,
	// RIGHT_ANKLE, RIGHT_FOOT
	skeleton.GetSkeletonJointPosition(user, XN_SKEL_HEAD, headPos);
	skeleton.GetSkeletonJointPosition(user, XN_SKEL_TORSO, torsoPos);
	skeleton.GetSkeletonJointPosition(user, XN_SKEL_LEFT_SHOULDER, leftPos);
	skeleton.GetSkeletonJointPosition(user, XN_SKEL_RIGHT_SHOULDER, rightPos);

	// Get the relevant coordinate for each joint (X, Y, or Z)
	head	= headPos.position.Z;
	torso	= torsoPos.position.Z;
	center	= torsoPos.position.X;
	left	= leftPos.position.Z;
	right	= rightPos.position.Z;
	
	// Determine defined positions based on tolerances defined in monitor.h
	if(head - LAYING_TOLERANCE > torso) {
		position = LAYING;
		out = false;
		
	} else if(	left < right - TURNED_TOLERANCE || 
				left > right + TURNED_TOLERANCE	) {
		position = TURNED;
		
	} else {
		position = FORWARD;
	}
	
	// Set/Check the patient vs the bed location
	if( (!bedSet) && position == LAYING ) {
		// If the bed location is not yet set, then set the bed at the patients torso X coordinate
		bed = center;
		bedSet = true;
		
	} else if( bedSet ) {
		// The patient is out of bed if they are outside the BED_TOLERANCE defined in monitor.h
		out = ( center < bed - BED_TOLERANCE || center > bed + BED_TOLERANCE );
	}
	
	return position;
}
Exemple #2
0
std::vector<std::vector<XnPoint3D> > KinectControl::getSkeleton()
{
    SkeletonCapability skeleton = user_generator.GetSkeletonCap();

    XnUserID user_id[15];
    XnUInt16 user_count = sizeof(user_id) / sizeof(user_id[0]);

    XnStatus nRetVal = user_generator.GetUsers(user_id, user_count);
    CHECK_RC(nRetVal, "Get Users");

    // 全ユーザ
    std::vector<std::vector<XnPoint3D> > skeletons;

    for(int i = 0; i < user_count; ++i)
    {
        // i番目のユーザがトラッキングされていたら
        if(skeleton.IsTracking(user_id[i]))
        {
            // 個別ユーザ
            std::vector<XnPoint3D> user_skeleton;

            // 関節は全てで24個
            XnSkeletonJointPosition joint[24];

            // [0]はCenter of Mass
            XnPoint3D pt[25];

            for(int j = 1; j < 25; ++j)
            {
                skeleton.GetSkeletonJointPosition(user_id[i], (XnSkeletonJoint)(j), joint[j - 1]);
                pt[j] = joint[j - 1].position;
            }

            user_generator.GetCoM(user_id[i], pt[0]);
            depth_generator.ConvertRealWorldToProjective(25, pt, pt);

            for(int j = 0; j < 25; ++j)
                user_skeleton.push_back(pt[j]);

            skeletons.push_back(user_skeleton);
        }
    }

    return skeletons;
}
/**
 *  Load actual joint positions.
 *
 *  Load the position of the joints in the joint array.
 *
 *  @param player is the player ID who needs to load the joints
 *  from.
 *  @param skelCap is the skeletonCapability taken from the User
 *  Generator.
 */
void NeutralModel :: loadJoints (XnUserID player, SkeletonCapability skelCap)
{
    // Skeleton Joint.
    XnSkeletonJointPosition jointPos;

    if (skelCap.IsTracking(player)) {

        // Get skeleton jointPos positions.
        skelCap.GetSkeletonJointPosition(
                player, 
                XN_SKEL_HEAD, 
                jointPos
        );
        joint[HEAD] = jointPos.position;

        skelCap.GetSkeletonJointPosition(
                player, 
                XN_SKEL_NECK, 
                jointPos
        );
        joint[NECK] = jointPos.position;

        skelCap.GetSkeletonJointPosition(
                player, 
                XN_SKEL_LEFT_SHOULDER, 
                jointPos
        );
        joint[LSHOULDER] = jointPos.position;

        skelCap.GetSkeletonJointPosition(
                player, 
                XN_SKEL_RIGHT_SHOULDER, 
                jointPos
        );
        joint[RSHOULDER] = jointPos.position;

        skelCap.GetSkeletonJointPosition(
                player, 
                XN_SKEL_TORSO, 
                jointPos
        );
        joint[TORSO] = jointPos.position;

        skelCap.GetSkeletonJointPosition(
                player, 
                XN_SKEL_LEFT_ELBOW, 
                jointPos
        );
        joint[LELBOW] = jointPos.position;

        skelCap.GetSkeletonJointPosition(
                player, 
                XN_SKEL_RIGHT_ELBOW, 
                jointPos
        );
        joint[RELBOW] = jointPos.position;

        skelCap.GetSkeletonJointPosition(
                player, 
                XN_SKEL_LEFT_HAND, 
                jointPos
        );
        joint[LHAND] = jointPos.position;

        skelCap.GetSkeletonJointPosition(
                player, 
                XN_SKEL_RIGHT_HAND, 
                jointPos
        );
        joint[RHAND] = jointPos.position;

        skelCap.GetSkeletonJointPosition(
                player, 
                XN_SKEL_LEFT_HIP, 
                jointPos
        );
        joint[LHIP]  = jointPos.position;

        skelCap.GetSkeletonJointPosition(
                player, 
                XN_SKEL_RIGHT_HIP, 
                jointPos
        );
        joint[RHIP]  = jointPos.position;

        skelCap.GetSkeletonJointPosition(
                player, 
                XN_SKEL_LEFT_KNEE, 
                jointPos
        );
        joint[LKNEE] = jointPos.position;

        skelCap.GetSkeletonJointPosition(
                player, 
                XN_SKEL_RIGHT_KNEE, 
                jointPos
        );
        joint[RKNEE] = jointPos.position;

        skelCap.GetSkeletonJointPosition(
                player, 
                XN_SKEL_LEFT_FOOT, 
                jointPos
        );
        joint[LFOOT]  = jointPos.position;

        skelCap.GetSkeletonJointPosition(
                player, 
                XN_SKEL_RIGHT_FOOT, 
                jointPos
        );
        joint[RFOOT]  = jointPos.position;

        nm_DepthGenerator.ConvertRealWorldToProjective(15, joint, joint); 
    }


}