Wednesday, March 27, 2013

Joint Angle Estimation for the Index Finger

Earlier today I implemented a way to map end-effector positions of the index finger from the Leap Motion controller to a target point visualized as a unit-radius sphere in Maya. Each frame update from the Leap Motion controller is first processed for the presence of fingers. If fingers exist, the fingers are sorted by their x-coordinate values. This facilitates selecting the index finger using index position '1' (the thumb lies in position '0', the pinky in position '4', etc.). Using this indexed array, we isolate the index finger, take its tip position and subtract the Leap's detected palm position from this value. The result gives us the direction vector of the index finger. 

The direction vector is useful for a number of reason. First, it describes the way the finger is positioned relative to the palm in space. Second, its length gives us information about the bend of the finger. We consider the length of the finger with an open, flat palm (all fingers extended) to be our base length. In every frame, we can use the current length of the direction vector to determine a target position for the  sphere in Maya. The smaller the length of the direction vector, the more likely the finger is to be bent. 

With this length aspect in mind, I devised a way to get a base length of the index finger. This is the length that will serve as the means of comparing all subsequent lengths from direction vectors. The purpose of the comparison will will become clearer in a moment. Calculating the base length is simple a process that samples the first 1000 frames in which fingers are present, determines their direction vectors, computes their lengths and average all of the values for each individual finger.  After the average length is calculated, the process of relaying position updates to Maya remains the same; however, there is one additional piece of information. We now send along lengthRatio, the ratio of the finger's length in the current frame to the base length. 

In Maya, we maintain the length of the joint chain (this can be calculated at run time if need be). When we receive a position update from the Leap with the direction vector and a lengthRatio, we normalize the direction vector and multiply it by the product of joint chain length and the lengthRatio.  We now need to obtain the position of the target point relative to the base of the joint chain using this direction vector. This is accomplished by adding the position of the joint chain base to the direction vector. The result is now a target positon mapped from the Leap coordinate space to Maya coordinate space with respect to the joint chain. We apply a translation transformation to the target point sphere using the  (xform) command. This then triggers a function call to perform Cyclic Coordinate Descent for estimating the joint bend angles. 

The reasoning behind using the lengthRatio, is simply to allow us to map a wider range of motion into Maya. Applying only the joint chain length to the unit direction vector tells us nothing about how a finger is actually bent. In fact, its sole application keeps the position of the target point on the surface of a sphere with a radius equal to the joint chain length and base at the joint chain base. The lengthRatio, on the contrary, describes how the target point sphere should be positioned on the joint chain sphere's surface (ratio equal to 1) or inside of the sphere (ratio is less than 1). 

One potential issue with this method is that the sampling/averaging process is (of course) not an exact measurement. Namely, if the user loosens their hand in the initial sampling process, the average length will be smaller than it should be. When the user decides to fully extend their fingers and open their palm during normal frame updates, the ratio will be greater than 1 causing positioning of the target point to be out of reach with respect to the joint chain length. This is a minor issue- we easily handle this occurrence using a projection procedure. If the position of a target point lies outside of the reach of the joint chain, we project that point onto its respective location on the surface of a sphere that has a radius equal to the joint chain length and a center at the base of the joint chain.

No comments:

Post a Comment