예제 #1
0
void glutDisplay (void)
{
	xn::SceneMetaData sceneMD;
	xn::DepthMetaData depthMD;
  
  g_kinect_controller.getContext().WaitAndUpdateAll();
  g_skeleton_tracker.processKinect(g_kinect_controller);
  g_kinect_controller.getDepthGenerator().GetMetaData(depthMD);
  g_kinect_controller.getUserGenerator().GetUserPixels(0, sceneMD);  
	
	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// Setup the OpenGL viewpoint
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();

	glOrtho(0, depthMD.XRes(), depthMD.YRes(), 0, -1.0, 1.0);
  
  glDisable(GL_TEXTURE_2D);
  
  kinect_display_drawDepthMapGL(depthMD, sceneMD);
	kinect_display_drawSkeletonGL(g_kinect_controller.getUserGenerator(),
                                g_kinect_controller.getDepthGenerator());  
  
	glutSwapBuffers();
}
예제 #2
0
void glutIdle (void)
{
  	g_kinect_controller.getContext().WaitAndUpdateAll();
  	g_skeleton_tracker.processKinect(g_kinect_controller);

	glutSetWindow(depth_window);
	glutPostRedisplay();

	glutSetWindow(rgb_window);
	glutPostRedisplay();
}
void getSkeleton (void)
{
	xn::SceneMetaData sceneMD;
	xn::DepthMetaData depthMD;
  
  g_kinect_controller.getContext().WaitAndUpdateAll();
  g_skeleton_tracker.processKinect(g_kinect_controller);
  g_kinect_controller.getDepthGenerator().GetMetaData(depthMD);
  g_kinect_controller.getUserGenerator().GetUserPixels(0, sceneMD);  
	
	
/* ADDED */
	char strLabel[50] = "";
	XnUserID aUsers[15];
	XnUInt16 nUsers = 15;
	(g_kinect_controller.getUserGenerator()).GetUsers(aUsers, nUsers);
	for (int i = 0; i < nUsers; ++i)
	{
		if ((g_kinect_controller.getUserGenerator()).GetSkeletonCap().IsTracking(aUsers[i]))
		{
      // LEFT
			XnSkeletonJointPosition joint1, joint2;
			(g_kinect_controller.getUserGenerator()).GetSkeletonCap().GetSkeletonJointPosition(aUsers[i], XN_SKEL_LEFT_ELBOW, joint1);
			(g_kinect_controller.getUserGenerator()).GetSkeletonCap().GetSkeletonJointPosition(aUsers[i], XN_SKEL_LEFT_HAND, joint2);

			if (joint1.fConfidence < 0.5 || joint2.fConfidence < 0.5)
			{
				return;
			}

			XnPoint3D pt[2];
			pt[0] = joint1.position;
			pt[1] = joint2.position;

			g_kinect_controller.getDepthGenerator().ConvertRealWorldToProjective(2, pt, pt);
			std_msgs::Int32MultiArray l_array;
      l_array.data.clear();
      l_array.data.push_back(pt[1].X);
      l_array.data.push_back(pt[1].Y);
			l_hand_pub.publish(l_array);

      // RIGHT
      (g_kinect_controller.getUserGenerator()).GetSkeletonCap().GetSkeletonJointPosition(aUsers[i], XN_SKEL_RIGHT_ELBOW, joint1);
      (g_kinect_controller.getUserGenerator()).GetSkeletonCap().GetSkeletonJointPosition(aUsers[i], XN_SKEL_RIGHT_HAND, joint2);

      if (joint1.fConfidence < 0.5 || joint2.fConfidence < 0.5)
      {
        return;
      }

      pt[0] = joint1.position;
      pt[1] = joint2.position;

      g_kinect_controller.getDepthGenerator().ConvertRealWorldToProjective(2, pt, pt);
      std_msgs::Int32MultiArray r_array;
      r_array.data.clear();
      r_array.data.push_back(pt[1].X);
      r_array.data.push_back(pt[1].Y);
      r_hand_pub.publish(r_array);
    }
  }
}
void glutDisplay (void)
{
	xn::SceneMetaData sceneMD;
	xn::DepthMetaData depthMD;
  
  g_kinect_controller.getContext().WaitAndUpdateAll();
  g_skeleton_tracker.processKinect(g_kinect_controller);
  g_kinect_controller.getDepthGenerator().GetMetaData(depthMD);
  g_kinect_controller.getUserGenerator().GetUserPixels(0, sceneMD);  
	
	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// Setup the OpenGL viewpoint
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();

	glOrtho(0, depthMD.XRes(), depthMD.YRes(), 0, -1.0, 1.0);
  
  glDisable(GL_TEXTURE_2D);
  
  kinect_display_drawDepthMapGL(depthMD, sceneMD);
	kinect_display_drawSkeletonGL(g_kinect_controller.getUserGenerator(),
                                g_kinect_controller.getDepthGenerator());  
	
/* ADDED */
	char strLabel[50] = "";
	XnUserID aUsers[15];
	XnUInt16 nUsers = 15;
	(g_kinect_controller.getUserGenerator()).GetUsers(aUsers, nUsers);
	for (int i = 0; i < nUsers; ++i)
	{
		if ((g_kinect_controller.getUserGenerator()).GetSkeletonCap().IsTracking(aUsers[i]))
		{
      // LEFT
			XnSkeletonJointPosition joint1, joint2;
			(g_kinect_controller.getUserGenerator()).GetSkeletonCap().GetSkeletonJointPosition(aUsers[i], XN_SKEL_LEFT_ELBOW, joint1);
			(g_kinect_controller.getUserGenerator()).GetSkeletonCap().GetSkeletonJointPosition(aUsers[i], XN_SKEL_LEFT_HAND, joint2);

			if (joint1.fConfidence < 0.5 || joint2.fConfidence < 0.5)
			{
				return;
			}

			XnPoint3D pt[2];
			pt[0] = joint1.position;
			pt[1] = joint2.position;

			g_kinect_controller.getDepthGenerator().ConvertRealWorldToProjective(2, pt, pt);
			std_msgs::Int32MultiArray l_array;
      l_array.data.clear();
      l_array.data.push_back(pt[1].X);
      l_array.data.push_back(pt[1].Y);
			l_hand_pub.publish(l_array);

      // RIGHT
      (g_kinect_controller.getUserGenerator()).GetSkeletonCap().GetSkeletonJointPosition(aUsers[i], XN_SKEL_RIGHT_ELBOW, joint1);
      (g_kinect_controller.getUserGenerator()).GetSkeletonCap().GetSkeletonJointPosition(aUsers[i], XN_SKEL_RIGHT_HAND, joint2);

      if (joint1.fConfidence < 0.5 || joint2.fConfidence < 0.5)
      {
        return;
      }

      pt[0] = joint1.position;
      pt[1] = joint2.position;

      g_kinect_controller.getDepthGenerator().ConvertRealWorldToProjective(2, pt, pt);
      std_msgs::Int32MultiArray r_array;
      r_array.data.clear();
      r_array.data.push_back(pt[1].X);
      r_array.data.push_back(pt[1].Y);
      r_hand_pub.publish(r_array);
    }
  }
  
	glutSwapBuffers();
}