forked from KinectToVR/KinectToVR
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKinectJointFilter.h
More file actions
81 lines (66 loc) · 2.56 KB
/
Copy pathKinectJointFilter.h
File metadata and controls
81 lines (66 loc) · 2.56 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
#pragma once
#include "stdafx.h"
#include <queue>
#include <assert.h>
#include <SFML/System/Vector3.hpp>
#include <KinectSettings.h>
#include "Kinect.h"
#include <openvr_math.h>
#include "VectorMath.h"
#include "SmoothingParameters.h"
// Joint Filter
// Courtesy of https://social.msdn.microsoft.com/Forums/en-US/045b058a-ae3a-4d01-beb6-b756631b4b42/joint-smoothing-code?forum=kinectv2sdk
// A holt double exponential smoothing filter
class DoubleExponentialFilterData
{
public:
sf::Vector3f rawPosition;
sf::Vector3f filteredPosition;
sf::Vector3f trend;
uint32_t frameCount;
};
class DoubleExponentialFilter
{
public:
DoubleExponentialFilter() { init(getDefaultSmoothingParams()); }
~DoubleExponentialFilter() { shutdown(); }
void init(SmoothingParameters p)
{
Reset(p.smoothing, p.correction, p.prediction, p.jitterRadius, p.maxDeviationRadius);
}
void init(float fSmoothing = 0.25f, float fCorrection = 0.25f, float fPrediction = 0.25f,
float fJitterRadius = 0.03f, float fMaxDeviationRadius = 0.05f)
{
Reset(fSmoothing, fCorrection, fPrediction, fJitterRadius, fMaxDeviationRadius);
}
void shutdown()
{
}
void Reset(float fSmoothing = 0.25f, float fCorrection = 0.25f, float fPrediction = 0.25f,
float fJitterRadius = 0.03f, float fMaxDeviationRadius = 0.05f)
{
assert(filteredJointPoints);
assert(pointHistory);
m_fMaxDeviationRadius = fMaxDeviationRadius;
// Size of the max prediction radius Can snap back to noisy data when too high
m_fSmoothing = fSmoothing; // How much smothing will occur. Will lag when too high
m_fCorrection = fCorrection; // How much to correct back from prediction. Can make things springy
m_fPrediction = fPrediction; // Amount of prediction into the future to use. Can over shoot when too high
m_fJitterRadius = fJitterRadius;
// Size of the radius where jitter is removed. Can do too much smoothing when too high
memset(filteredJointPoints, 0, sizeof(sf::Vector3f) * JointType_Count);
memset(pointHistory, 0, sizeof(DoubleExponentialFilterData) * JointType_Count);
}
void update(IBody* pBody, bool newFrameArrived);
void update(Joint joints[], bool newFrameArrived);
const sf::Vector3f* GetFilteredJoints() const { return &filteredJointPoints[0]; }
private:
sf::Vector3f filteredJointPoints[JointType_Count];
DoubleExponentialFilterData pointHistory[JointType_Count];
float m_fSmoothing;
float m_fCorrection;
float m_fPrediction;
float m_fJitterRadius;
float m_fMaxDeviationRadius;
void update(Joint joints[], UINT JointID, SmoothingParameters smoothingParams, bool newFrameArrived);
};