Nuitrack  1.4.1
3D Skeleton Tracking Middleware
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Properties Events Groups Pages
nuitrack_console_sample/src/main.cpp

Simple console sample.

See description: Nuitrack console sample

#include <nuitrack/Nuitrack.h>
#include <iomanip>
#include <iostream>
using namespace tdv::nuitrack;
void showHelpInfo()
{
std::cout << "Usage: nuitrack_console_sample [path/to/nuitrack.config]" << std::endl;
}
// Callback for the hand data update event
void onHandUpdate(HandTrackerData::Ptr handData)
{
if (!handData)
{
// No hand data
std::cout << "No hand data" << std::endl;
return;
}
auto userHands = handData->getUsersHands();
if (userHands.empty())
{
// No user hands
return;
}
auto rightHand = userHands[0].rightHand;
if (!rightHand)
{
// No right hand
std::cout << "Right hand of the first user is not found" << std::endl;
return;
}
std::cout << std::fixed << std::setprecision(3);
std::cout << "Right hand position: "
"x = " << rightHand->xReal << ", "
"y = " << rightHand->yReal << ", "
"z = " << rightHand->zReal << std::endl;
}
int main(int argc, char* argv[])
{
showHelpInfo();
std::string configPath = "";
if (argc > 1)
configPath = argv[1];
// Initialize Nuitrack
try
{
Nuitrack::init(configPath);
}
catch (const Exception& e)
{
std::cerr << "Can not initialize Nuitrack (ExceptionType: " << e.type() << ")" << std::endl;
return EXIT_FAILURE;
}
// Create HandTracker module, other required modules will be
// created automatically
auto handTracker = HandTracker::create();
// Connect onHandUpdate callback to receive hand tracking data
handTracker->connectOnUpdate(onHandUpdate);
// Start Nuitrack
try
{
}
catch (const Exception& e)
{
std::cerr << "Can not start Nuitrack (ExceptionType: " << e.type() << ")" << std::endl;
return EXIT_FAILURE;
}
int errorCode = EXIT_SUCCESS;
while (true)
{
try
{
// Wait for new hand tracking data
Nuitrack::waitUpdate(handTracker);
}
{
std::cerr << "LicenseNotAcquired exception (ExceptionType: " << e.type() << ")" << std::endl;
errorCode = EXIT_FAILURE;
break;
}
catch (const Exception& e)
{
std::cerr << "Nuitrack update failed (ExceptionType: " << e.type() << ")" << std::endl;
errorCode = EXIT_FAILURE;
}
}
// Release Nuitrack
try
{
}
catch (const Exception& e)
{
std::cerr << "Nuitrack release failed (ExceptionType: " << e.type() << ")" << std::endl;
errorCode = EXIT_FAILURE;
}
return errorCode;
}