int main(int argc, char** argv)
{
	nite::HandTracker handTracker;
	nite::Status niteRc;

	niteRc = nite::NiTE::initialize();
	if (niteRc != nite::STATUS_OK)
	{
		printf("NiTE initialization failed\n");
		return 1;
	}

	niteRc = handTracker.create();
	if (niteRc != nite::STATUS_OK)
	{
		printf("Couldn't create user tracker\n");
		return 3;
	}

	handTracker.startGestureDetection(nite::GESTURE_WAVE);
	handTracker.startGestureDetection(nite::GESTURE_CLICK);
	printf("\nWave or click to start tracking your hand...\n");

	nite::HandTrackerFrameRef handTrackerFrame;
	while (!wasKeyboardHit())
	{
		niteRc = handTracker.readFrame(&handTrackerFrame);
		if (niteRc != nite::STATUS_OK)
		{
			printf("Get next frame failed\n");
			continue;
		}

		const nite::Array<nite::GestureData>& gestures = handTrackerFrame.getGestures();
		for (int i = 0; i < gestures.getSize(); ++i)
		{
			if (gestures[i].isComplete())
			{
				nite::HandId newId;
				handTracker.startHandTracking(gestures[i].getCurrentPosition(), &newId);
			}
		}

		const nite::Array<nite::HandData>& hands = handTrackerFrame.getHands();
		for (int i = 0; i < hands.getSize(); ++i)
		{
			const nite::HandData& hand = hands[i];
			if (hand.isTracking())
			{
				printf("%d. (%5.2f, %5.2f, %5.2f)\n", hand.getId(), hand.getPosition().x, hand.getPosition().y, hand.getPosition().z);
			}
		}
	}

	nite::NiTE::shutdown();

}
コード例 #2
0
ファイル: main.cpp プロジェクト: snowhong/backup
int main(int argc, char** argv)
{
	nite::UserTracker userTracker;
	nite::Status niteRc;

	nite::NiTE::initialize();

	niteRc = userTracker.create();
	if (niteRc != nite::STATUS_OK)
	{
		printf("Couldn't create user tracker\n");
		return 3;
	}
	printf("\nStart moving around to get detected...\n(PSI pose may be required for skeleton calibration, depending on the configuration)\n");

	nite::UserTrackerFrameRef userTrackerFrame;
	while (!wasKeyboardHit())
	{
		niteRc = userTracker.readFrame(&userTrackerFrame);
		if (niteRc != nite::STATUS_OK)
		{
			printf("Get next frame failed\n");
			continue;
		}

		const nite::Array<nite::UserData>& users = userTrackerFrame.getUsers();
		for (int i = 0; i < users.getSize(); ++i)
		{
			const nite::UserData& user = users[i];
			updateUserState(user,userTrackerFrame.getTimestamp());
			if (user.isNew())
			{
				userTracker.startSkeletonTracking(user.getId());
			}
			else if (user.getSkeleton().getState() == nite::SKELETON_TRACKED)
			{
				const nite::SkeletonJoint& head = user.getSkeleton().getJoint(nite::JOINT_HEAD);
				if (head.getPositionConfidence() > .5)
				printf("%d. (%5.2f, %5.2f, %5.2f)\n", user.getId(), head.getPosition().x, head.getPosition().y, head.getPosition().z);
			}
		}

	}

	nite::NiTE::shutdown();

}
コード例 #3
0
ファイル: main.cpp プロジェクト: 1170390/OpenNI2
int main()
{

	closest_point::ClosestPoint closestPoint;

	if (!closestPoint.isValid())
	{
		printf("ClosestPoint: error in initialization\n");
		return 1;
	}

	MyMwListener myListener;

	closestPoint.setListener(myListener);

	while (!wasKeyboardHit())
	{
		Sleep(1000);
	}

	closestPoint.resetListener();

	return 0;
}
コード例 #4
0
ファイル: main.cpp プロジェクト: aldebaran/openni2
int main(int argc, char * argv[])
{
  std::string path("recording.oni");
  int duration = -1;
  if(argc == 2)
  {
    duration = 1000*atoi(argv[1]); // convert to ms
  }

  if(duration > 0)
  {
    std::cout << "Will start a recording in " << path
              << " of " << duration/1000 << " seconds" << std::endl;
  }
  else
  {
    std::cout << "Will start a recording in " << path << " until keyboard hit" << std::endl;
  }

  // 1 - Initialize OpenNI
  openni::Status rc = openni::OpenNI::initialize();
  if (rc != openni::STATUS_OK)
  {
    std::cerr << "Initialize failed: "
              << openni::OpenNI::getExtendedError() << std::endl;
    return 1;
  }

  // 2 - Open device
  openni::Device device;
  rc = device.open(openni::ANY_DEVICE);
  if (rc != openni::STATUS_OK)
  {
    std::cerr << "Couldn't open device: "
              << openni::OpenNI::getExtendedError() << std::endl;
    return 2;
  }

  // 3 - Create stream
  openni::VideoStream depth;
  if (device.getSensorInfo(openni::SENSOR_DEPTH) != NULL)
  {
    rc = depth.create(device, openni::SENSOR_DEPTH);
    if (rc != openni::STATUS_OK)
    {
      std::cerr << "Couldn't create depth stream: "
                << openni::OpenNI::getExtendedError() << std::endl;
      return 3;
    }
  }

  // 4 - Create recording
  openni::Recorder rec;
  rec.create(path.c_str());
  rec.attach(depth, false);

  // 5 - Start stream
  rc = depth.start();
  if (rc != openni::STATUS_OK)
  {
    std::cerr << "Couldn't start the depth stream: "
              << openni::OpenNI::getExtendedError() << std::endl;
    return 4;
  }

  // 6 - Start recording
  rec.start();

  timeval tv_init;
  gettimeofday(&tv_init, 0);

  bool running = true;
  int recordingTime = 0; // in milliseconds
  while(running)
  {
    Sleep(100); // in milliseconds

    timeval tv;
    gettimeofday(&tv, 0);
    recordingTime = (tv.tv_sec-tv_init.tv_sec)*1000+(tv.tv_usec-tv_init.tv_usec)/1000;

    // stop condition
    if(duration > 0 && recordingTime >= duration)
      running = false;
    if(duration <= 0 && wasKeyboardHit())
      running = false;
  }

  std::cout << "Recording stopped (" << recordingTime << " ms recorded)" << std::endl;


  // 7 - Stop recording
  rec.stop();

  // 8 - Cleanup
  rec.destroy();
  depth.stop();
	depth.destroy();
	device.close();
	openni::OpenNI::shutdown();

	return 0;
}