This example can be found in Development\images\images.cpp.
This example shows how to enable image transfer on the PST Tracker and how to use the PST SDK to retrieve images. Images are 8 bit grayscale and are stored as an unsigned char* without memory alignment or padding.
#ifdef WIN32
#include <windows.h>
#endif
static void Exithandler(int sig);
#ifdef WIN32
BOOL WINAPI ConsoleHandler(DWORD CEvent)
{
Exithandler(CEvent);
return TRUE;
}
#endif
#include <memory>
#include <iostream>
static bool running = true;
static const uint32_t numberOfSamplesToGrab = 1000;
{
{
static uint32_t samplesGrabbed = 0;
if (samplesGrabbed++ >= numberOfSamplesToGrab)
running = false;
}
} listener;
std::shared_ptr<PSTech::pstsdk::Tracker> pst;
static void Exithandler(int sig)
{
pst->Shutdown();
}
int main(int argc, char *argv[])
{
#ifdef WIN32
SetConsoleCtrlHandler((PHANDLER_ROUTINE)ConsoleHandler, TRUE);
#else
signal(SIGTERM, Exithandler);
signal(SIGKILL, Exithandler);
signal(SIGQUIT, Exithandler);
signal(SIGINT, Exithandler);
#endif
try
{
pst = std::make_shared<PSTech::pstsdk::Tracker>();
std::cout << "Running PST Server version " << pst->GetVersionInfo() << "\n";
pst->AddTrackerListener(&listener);
pst->Start();
std::cout << "System check: " << (int)pst->Systemcheck() << "\n\n";
std::cout << "***************************\n\n";
pst->SetFramerate(60);
std::cout << "Current frame rate: " << pst->GetFramerate() << " Hz\n\n";
pst->EnableImageTransfer();
std::cout << "Enabled image transfer. Current frame rate: " << pst->GetFramerate() << " Hz\n\n";
std::cout << "***************************\n\n";
for (int i = 0; i < 100; ++i)
{
bool succes = pst->GetImage(images);
std::cout << "Retrieval operation " << ((succes) ? "successful!\n" : "unsuccesful!\n\n");
if (succes)
{
std::cout <<
"Retrieved " << images.
images.size() <<
" image(s) of size: " << images.
width <<
" X " << images.
height <<
"\n\n";
}
}
Sleep(5000);
bool succes = pst->GetImage(images);
std::cout << "Retrieval operation " << ((succes) ? "successful!\n" : "unsuccesful!");
if (succes)
{
std::cout <<
"Retrieved " << images.
images.size() <<
" image(s) of size: " << images.
width <<
" X " << images.
height <<
"\n\n";
}
while (running)
{
Sleep(100);
}
}
{
}
pst->Shutdown();
std::cout << "Press enter to continue...\n";
std::cin.get();
return 0;
}