2

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!

Andreas Köberle
  • 106,652
  • 57
  • 273
  • 297
Dream Lane
  • 1,282
  • 5
  • 16
  • 27

2 Answers2

3

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!

Adam Liss
  • 47,594
  • 12
  • 108
  • 150
1

Wouldn't the simplest way be to work out the vector difference i.e. subtract one from the other, and decide how big a difference is significant enough to judge it an abrupt change of direction.

That would be computationally inexpensive.

EDIT: just to expand on that a bit, 2 vectors of similar direction have a near-zero vector difference. Two vectors in opposing directions will have a large vector difference.

e.g.

 (4,4) - (3,3) = (1,1)
 (4,0) - (0,4) = (4,-4)
 (4,4) - (-4,-4) = (8,8)

(I know that's 2D but the principles are the same.)

Charles Goodwin
  • 6,402
  • 3
  • 34
  • 63
  • I'm trying to chew on this a bit... But my "vectors" actually only represent points in 3d space so to see a change in direction won't I have to perform some math on at least 3 points? Sorry if I was not clear on my description of the PVectors. I've edited the post – Dream Lane Jul 01 '11 at 02:14