Consider your input values (these jump positions) as a signal with low-frequency and low-frequency parts. The low frequencies represent a rough position / movement, while the high-frequency parts contain rapid spasmodic movement at shorter distances.
So you need or need to look for a lowpass filter. This filters out the high-frequency parts and leaves a rough (but accurate, like Kinect) position if you manage to adjust it using the correct parameter. This parameter is the crossover frequency for the filter. You need to play a little and you will see.
An example implementation for discrete time values will be 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 the X and Y components of your position vectors into this function to smooth them ( input[0]
for X and input[1]
for Y, output[0]
and output[1]
are the results of the previous function call).
As I said, you need to find a good balance for the ALPHA
smoothing factor (0 ≤ ALPHA ≤ 1):
- Too large and the signal will not be smooth enough, the effect will not be sufficient
- Too small, and the signal will be smoothed "too much", the cursor will lag behind the movement of users, too much inertia.
(If you look at the formula newout = out + alpha * (in - out)
, you will see that with an alpha value of 0 you again take the old out
value, so the value will never change, and with a value of 1 you newout = out + in - out
, this means that you do not smooth out anything, but always take the latest value)
source share