Consider your input values (those jumping positions) as a signal with both low and high frequency parts. The low frequencies represent the rough position/movement while the high frequency parts contain the fast jumping within smaller distances.
So what you need or look for is a low pass filter. That filters out the high frequency parts and leaves the rough (but as accurate as the Kinect can get) position over, if you manage to set it up with the right parameter. This parameter is the crossover frequency for the filter. You have to play around a bit and you will see.
An implementation example for time-discrete values would be from here (originally from wikipedia):
static final float ALPHA = 0.15f;
protected float[] lowPass( float[] input, float[] output ) {
if ( output == null ) return input;
for ( int i=0; i<input.length; i++ ) {
output[i] = output[i] + ALPHA * (input[i] - output[i]);
}
return output;
}
You can put the last values of both the X and Y components of your position vectors into this function to smooth them out (input[0]
for X and input[1]
for Y, output[0]
and output[1]
are results of the previous function call).
Like I already said, you have to find a good balance for the smoothing factor ALPHA
(0 ≤ ALPHA ≤ 1):
- Too big and the signal will not get smoothed enough, the effect wont be sufficient
- Too small and the signal will be smoothed 'too much', the cursor will lag behind the users movement, too much inertia
(If you look at the formula newout = out + alpha * (in - out)
, you see that with a alpha value of 0, you just take the old out
value again, therefore the value will never change; while with a value of 1 you have newout = out + in - out
that means you dont smooth anything but always take the newest value)