I am working on a piece of software written in Java that uses some processing.core library classes and simpleopenni to track a user's hand with the XBOX Kinect.
What I am trying to figure out is how to determine when a user's hand movement changes direction abruptly.
What I have at my disposal currently is an array of PVectors (essentially a vector of x,y,and z coordinates: A point in 3d space) that record the user's hand position for the past 30 frames or so.
I imagine that there must be a way to obtain a value that represents the amount of directional change in nearly real-time given the most recent few points recorded. Maybe fit a curve and take some derivatives?
Ideally the solution should not be very computationally expensive, as I am trying to implement a real-time worthy solution.
Any direction that you can offer will be greatly appreciated!
Let the position now (that is, 0 frames ago) be (x0, y0, z0)
Let the position n
frames ago be (xn, yn, zn)
.
Let the position 2n
frames ago be (xm, ym, zm)
.
Then the change in position between frames 2n
and n
is (xn-xm, yn-ym, zn-zm)
.
You can think of this as the average velocity during those n
frames.
And the change in position between n
and now is (x0-xn, y0-yn, z0-zn)
.
This represents the average velocity during the next n
frames.
Now you have the velocity for the n
frames that ended n
frames ago, and you have the velocity for the n
frames that just ended now.
The change in velocity during the last n
frames must be the difference between those two vectors. For each coordinate:
Ax = (x0-xn) - (xn-xm) = x0 -2xn + xm
Ay = (y0-yn) - (yn-ym) = y0 -2yn + ym
Az = (z0-xn) - (zn-zm) = z0 -2zn + zm
The magnitude of the acceleration is |A| = sqrt( (Ax)^2 + (Ay)^2 + (Az)^2 )
If you're concerned only with "large" changes and prefer speed over accuracy, you may be able to get away with A' = (Ax)^2 + (Ay)^2 + (Az)^2
or even A" = abs(Ax) + abs(Ay) + abs(Az)
The idea is that you want each component to contribute to the whole regardless of whether it's positive or negative, so you "force" it to be positive either by squaring it or taking its absolute value.
Hope that helps!