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.
When compiling and running this example, please make sure that the required dependencies can be found by the executable (e.g. by copying the Redist directory into the build directory. When the PST SDK has been installed through the PST Software Suite installer the Redist folder can be found in the Development folder.).
#ifdef WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif
static void Exithandler(int sig);
#ifdef WIN32
BOOL WINAPI ConsoleHandler(DWORD CEvent)
{
Exithandler(CEvent);
return TRUE;
}
#endif
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <signal.h>
static sig_atomic_t running = 1;
static const uint32_t numberOfSamplesToGrab = 1000;
{
static uint32_t samplesGrabbed = 0;
if (samplesGrabbed++ >= numberOfSamplesToGrab)
running = 0;
}
static void Exithandler(int sig)
{
exit(0);
}
void PrintLastErrorMessage()
{
char* last_error_message = NULL;
{
last_error_message = "Failed to allocate memory error.";
}
printf("last error message: %s \n", last_error_message);
}
{
{
PrintLastErrorMessage();
exit(status);
}
}
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
#ifdef WIN32
#else
CheckErrorCode(
pst_tracker_init4(&ctracker,
"",
"config.cfg",
"models.db", argv[1]));
#endif
char* version_string;
printf("Running PST Server version %s \n", version_string);
printf("***************************\n\n");
double fps;
printf("Current frame rate: %f Hz\n\n", fps);
printf("Enabled image transfer. Current frame rate: %f Hz\n\n", fps);
printf("***************************\n\n");
for (int i = 0; i < 100; ++i)
{
printf("Retrieval operation successful!\n");
#ifdef WIN32
Sleep(17);
#else
usleep(17000);
#endif
}
printf("Waiting 5 seconds for image transfer to be automatically disabled...\n\n");
#ifdef WIN32
Sleep(5000);
#else
sleep(5);
#endif
printf("Retrieval operation successful!\n");
while (running == 1)
{
#ifdef WIN32
Sleep(100);
#else
usleep(100000);
#endif
}
printf("Press enter to continue...\n");
getchar();
return 0;
}
void pst_image_init(PstImage *image)
void pst_image_destroy(PstImage *image)
EPstErrorStatus pst_tracker_get_pst_image(const PstTracker *ctracker, PstImage *image)
Retrieve images from the connected PST Tracker.
EPstErrorStatus pst_tracker_get_framerate(const PstTracker *ctracker, double *fps)
Get current frame rate.
EPstErrorStatus pst_tracker_init(PstTracker *ctracker)
This function initializes the tracker object.
EPstErrorStatus pst_alloc_and_get_last_error_message(char **cstring)
This function returns the last error message that was recorded by the system.
EPstErrorStatus pst_tracker_init4(PstTracker *ctracker, const char path[], const char config_file[], const char db_file[], const char grabber_name[])
This function initializes the tracker object.
void pst_tracker_destroy(PstTracker *ctracker)
void pst_sdk_shutdown()
Shutdown the tracking system, stopping tracking.
EPstErrorStatus pst_tracker_alloc_and_get_version_info(const PstTracker *ctracker, char **version_string)
Get version information of the SDK.
void pst_free(void *data)
Free data allocated by the PST SDK.
EPstErrorStatus pst_tracker_start(PstTracker *ctracker)
Start tracking.
EPstErrorStatus pst_tracker_set_framerate(PstTracker *ctracker, double fps)
Set tracker frame rate.
EPstErrorStatus pst_tracker_enable_image_transfer(PstTracker *ctracker)
Enable image transfer from the PST Tracker.
EPstErrorStatus pst_tracker_add_tracker_data_callback(PstTracker *ctracker, void(*on_tracker_data)(const PstTrackerData *, EPstErrorStatus))
Add a callback function for tracker data.
EPstStatusMessage pst_tracker_system_check(const PstTracker *ctracker)
Check if the tracker is running correctly.
EPstErrorStatus
Tracker error messages enum class.
Definition pstsdk_c.h:44
@ PST_ERROR_STATUS_OK
Definition pstsdk_c.h:45
Images retrieved from the tracker.
Definition pstsdk_c.h:118
size_t width
Definition pstsdk_c.h:119
size_t height
Definition pstsdk_c.h:120
size_t number_of_images
Definition pstsdk_c.h:121
Tracking information retrieved from tracker.
Definition pstsdk_c.h:248
Main PST SDK struct for tracker communication.
Definition pstsdk_c.h:264