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
nframes ago be(xn, yn, zn).Let the position
2nframes ago be(xm, ym, zm).Then the change in position between frames
2nandnis(xn-xm, yn-ym, zn-zm).You can think of this as the average velocity during those
nframes.And the change in position between
nand now is(x0-xn, y0-yn, z0-zn).This represents the average velocity during the next
nframes.Now you have the velocity for the
nframes that endednframes ago, and you have the velocity for thenframes that just ended now.The change in velocity during the last
nframes must be the difference between those two vectors. For each coordinate:Ax = (x0-xn) - (xn-xm) = x0 -2xn + xmAy = (y0-yn) - (yn-ym) = y0 -2yn + ymAz = (z0-xn) - (zn-zm) = z0 -2zn + zmThe 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)^2or 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!