-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcallbacks.cpp
More file actions
92 lines (84 loc) · 3.36 KB
/
callbacks.cpp
File metadata and controls
92 lines (84 loc) · 3.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <XnCppWrapper.h>
#include "SensorDevice.h"
//Callbacks for calibration events
void XN_CALLBACK_TYPE UserCalibration_CalibrationStart(xn::SkeletonCapability& capability, XnUserID nId, void* pCookie)
{
printf("Calibration started for user %d\n", nId);
}
void XN_CALLBACK_TYPE UserCalibration_CalibrationComplete(xn::SkeletonCapability& capability, XnUserID nId, XnCalibrationStatus eStatus, void* pCookie)
{
SensorDevice* sensor = (SensorDevice*) pCookie;
if (eStatus == XN_CALIBRATION_STATUS_OK)
{
// Calibration succeeded
printf("Calibration completed: Start tracking user %d\n", nId);
sensor->getUserGenerator()->GetSkeletonCap().StartTracking(nId);
//are we saving calibration data
if(sensor->getSaveCalibration())
{
// Save user's calibration to file
XnStatus rc = sensor->getUserGenerator()->GetSkeletonCap().SaveCalibrationDataToFile(nId, sensor->getCalibrationFilename());
if (rc != XN_STATUS_OK)
printf("Unable to save calibration data to file: %s! Check permissions or give filename as argument.\n", sensor->getCalibrationFilename());
else
printf("Saved calibration data to file: %s\n", sensor->getCalibrationFilename());
}
}
else
{
// Calibration failed
printf("Calibration failed for user %d\n", nId);
if (sensor->getNeedCalibrationPose())
{
sensor->getUserGenerator()->GetPoseDetectionCap().StartPoseDetection(sensor->getPoseString(), nId);
}
else
{
sensor->getUserGenerator()->GetSkeletonCap().RequestCalibration(nId, TRUE);
}
}
}
// Callback: New user was detected
void XN_CALLBACK_TYPE User_NewUser(xn::UserGenerator& generator, XnUserID nId, void* pCookie)
{
SensorDevice* sensor = (SensorDevice*) pCookie;
printf("New User %d\n", nId);
// New user found
if (sensor->getNeedCalibrationPose())
{
sensor->getUserGenerator()->GetPoseDetectionCap().StartPoseDetection(sensor->getPoseString(), nId);
}
//autocalibrate
else
{
printf("Auto-calibrating user %d.\n", nId);
sensor->getUserGenerator()->GetSkeletonCap().RequestCalibration(nId,TRUE);
}
/*
// we are loading the calibration data from a file
else
{
printf("Loading calibration data from file: %s for user: %d.\n", sensor->getCalibrationFilename(), nId);
XnStatus rc = sensor->getUserGenerator()->GetSkeletonCap().LoadCalibrationDataFromFile(nId, sensor->getCalibrationFilename());
if (rc == XN_STATUS_OK)
{
// Make sure state is coherent
sensor->getUserGenerator()->GetPoseDetectionCap().StopPoseDetection(nId);
sensor->getUserGenerator()->GetSkeletonCap().StartTracking(nId);
}
}
*/
}
// Callback: An existing user was lost
void XN_CALLBACK_TYPE User_LostUser(xn::UserGenerator& generator, XnUserID nId, void* pCookie)
{
printf("Lost user %d\n", nId);
}
// Callback: Detected a pose
void XN_CALLBACK_TYPE UserPose_PoseDetected(xn::PoseDetectionCapability& capability, const XnChar* strPose, XnUserID nId, void* pCookie)
{
SensorDevice* sensor = (SensorDevice*) pCookie;
printf("Pose %s detected for user %d\n", sensor->getPoseString(), nId);
sensor->getUserGenerator()->GetPoseDetectionCap().StopPoseDetection(nId);
sensor->getUserGenerator()->GetSkeletonCap().RequestCalibration(nId, TRUE);
}