예제 #1
0
void drawSkeleton( nite::UserTrackerFrameRef& userFrame,
                   nite::UserTracker& userTracker,
                   cv::Mat& image)
{
    const nite::Array<nite::UserData>& users = userFrame.getUsers();
    for ( int i = 0; i < users.getSize(); ++i ) {
        const nite::UserData& user = users[i];
        if ( user.isNew() ) {
            userTracker.startSkeletonTracking( user.getId() );
            userTracker.startPoseDetection( user.getId(), nite::POSE_PSI);
            userTracker.startPoseDetection( user.getId(), nite::POSE_CROSSED_HANDS);
        }
        else if ( !user.isLost() ) {
            // skeletonの表示
            const auto skeleton = user.getSkeleton();
            if ( skeleton.getState() == nite::SkeletonState::SKELETON_TRACKED ) {
                for ( int j = 0; j < 15; j++ ) {
                    const auto joint = skeleton.getJoint((nite::JointType)j);
                    if ( joint.getPositionConfidence() >= 0.7f ) {
                        const auto position = joint.getPosition();
                        float x = 0, y = 0;
                        userTracker.convertJointCoordinatesToDepth(
                            position.x, position.y, position.z, &x, &y );

                        cv::circle( image, cvPoint( (int)x, (int)y ),
                            3, cv::Scalar( 0, 0, 255 ), 5 );
                    }
                }
            }
            // poseの表示
            const auto pose_psi = user.getPose(nite::POSE_PSI);
            if( pose_psi.isHeld() || pose_psi.isEntered() )
            {
                auto center = user.getCenterOfMass();
                float x = 0, y = 0;
                userTracker.convertJointCoordinatesToDepth(center.x, center.y, center.z, &x, &y);
                cv::putText(image, "PSI", cv::Point2f(x,y), cv::FONT_HERSHEY_SIMPLEX, 2, cv::Scalar(0xFF,0xFF,0xFF));
            }
            const auto pose_cross = user.getPose(nite::POSE_CROSSED_HANDS);
            if( pose_cross.isHeld() || pose_cross.isEntered() ){
                auto center = user.getCenterOfMass();
                float x = 0, y = 0;
                userTracker.convertJointCoordinatesToDepth(center.x, center.y, center.z, &x, &y);
                cv::putText(image, "Cross", cv::Point2f(x,y), cv::FONT_HERSHEY_COMPLEX, 2, cv::Scalar(0xFF,0xFF,0xFF));
            }
        }
    }
}
예제 #2
0
void CGraph::JointFun(const nite::UserTracker&usertracker, const nite::UserData&data, const int&mapx, const int&mapy)
{
	static const unsigned int total = JOINTDATA_SIZE - 2;
	float cood[3 * total];
	memset(cood, 0, sizeof(float) * 3 * total);
	for (int i = 0; i < total; i++)
	{
		//if ((i == SHOULDER_ASIDE || i == HEAD_ASIDE)) continue;
		x[i] = data.getSkeleton().getJoint(jType[i]).getPosition().x;
		y[i] = data.getSkeleton().getJoint(jType[i]).getPosition().y;
		z[i] = data.getSkeleton().getJoint(jType[i]).getPosition().z;
	}

	if (x[0] == 0 || y[0] == 0 || x[1] == 0 || y[1] == 0 || x[2] == 0 || y[2] == 0)
	{
		istracked = 0;
		m_angle = 0;
		return;
	}
	istracked = 1;
	/*if (abs(x[LEFT_SHOULDER] - x[RIGHT_SHOULDER]) <= 10)
	{
	m_playmode = PLAYMODE_DEPTH_SIDE;
	}
	else
	{
	m_playmode = PLAYMODE_DEPTH;
	}*/
	for (int i = 0; i < total; i++)
	{
		usertracker.convertJointCoordinatesToDepth(x[i], y[i], z[i], cood + 3 * i, cood + 3 * i + 1);
		cood[3 * i + 0] *= m_width*1.0 / mapx;
		cood[3 * i + 1] *= m_height*1.0 / mapy;
		cood[3 * i + 2] *= 0;
	}
	glColor3f(1, 0.5, 0);
	glEnable(GL_CULL_FACE);
	glPolygonMode(GL_FRONT, GL_FILL);
	glCullFace(GL_BACK);
	for (int i = 1; i < total; i++)
	{
		glPushMatrix();
		glLoadIdentity();
		glTranslatef(cood[i * 3], cood[i * 3 + 1], cood[i * 3 + 2]);
		glutSolidSphere(10, 100, 100);
		glPopMatrix();
	}
	glDisable(GL_CULL_FACE);

};