joint orientations and euler angles for bvh files

1,316 views
Skip to first unread message

Oriol Lopez

unread,
Apr 6, 2012, 4:57:39 PM4/6/12
to OpenNI
I'm trying to make bvh files from the data OpenNI provides, but I'm
stuck in two problems:

1- How can I get the euler angles I need? I tried Factorization in
RxRyRz order, following this: http://www.geometrictools.com/Documentation/EulerAngles.pdf
But nothing. This is the code:

// [[X1, Y1, Z1]
//RotMatrix = [X2, Y2, Z2]
// [X3, Y3, Z3]]
XnMatrix3X3 RotMatrix;
RotMatrix.elements[X1] = orientations.elements[0];
RotMatrix.elements[X2] = orientations.elements[1];
RotMatrix.elements[X3] = orientations.elements[2];
RotMatrix.elements[Y1] = orientations.elements[3];
RotMatrix.elements[Y2] = orientations.elements[4];
RotMatrix.elements[Y3] = orientations.elements[5];
RotMatrix.elements[Z1] = orientations.elements[6];
RotMatrix.elements[Z2] = orientations.elements[7];
RotMatrix.elements[Z3] = orientations.elements[8];

if(RotMatrix.elements[Z1] < 1)
{
if(RotMatrix.elements[Z1] > -1)
{
Ry = RadianToDegree(asin(RotMatrix.elements[Z1]));
Rx = RadianToDegree(atan2(-RotMatrix.elements[Z2],
RotMatrix.elements[Z3]));
Rz = RadianToDegree(atan2(-RotMatrix.elements[Y1],
RotMatrix.elements[X1]));
}
else //Z1 = -1
{
Ry = RadianToDegree(-pi/2);
Rx = RadianToDegree(-atan2(RotMatrix.elements[X2],
RotMatrix.elements[Y2]));
Rz = 0;
}
}
else //Z1 = +1
{
Ry = RadianToDegree(pi/2);
Rx = RadianToDegree(atan2(RotMatrix.elements[X2],
RotMatrix.elements[Y2]));
Rz = 0;
}


2- I need the angles for the root aswell (the hips, wich correspong to
the Waist in OpenNI), but OpenNI doesn't collect any data for it.
Should I be using the data obtained for the joint TORSO?

I looked into these threads, and seems that some people had my
problems time ago, but even following them I couldn't reach to a
solution. Does someone know how to do this?

Yassir Ennazk

unread,
Apr 7, 2012, 6:58:25 PM4/7/12
to openn...@googlegroups.com
Having the same problems here.
Had found this for the first problem : https://groups.google.com/d/msg/openni-dev/zLjmKs0XuVs/LD5p8wBJ5IMJ but haven't had enough time to test it yet.
Could you please confirm that it works ?
For the second problem I still got no luck.

Oriol Lopez

unread,
Apr 9, 2012, 8:15:47 AM4/9/12
to OpenNI
That's what I'm actually doing.
I just don't get what the joint orientation data means... Man this is
frustrating.

Dan

unread,
Apr 10, 2012, 9:01:54 AM4/10/12
to OpenNI
You said that you've tried the code and got nothing. What precisely is
breaking? Does it work correctly if you pass it an artificially
created matrix of known rotations? For example the following should
produce Rz of PI/2 (or 90 degrees) and Rx and Ry of 0. If that
doesn't work, then there's a bug in the code.

[[ 0 -1 0 ]
[ 1 0 0 ]
[ 0 0 1 ]]

On the second problem, you'll have to make some assumptions and
construct a frame for the pelvis. Typically, something like using the
left hip to right hip vector for X will work. Take the average of the
hips and use the vector from that to the neck for Y. Cross those two
to get Z.

dba

phil217

unread,
Apr 12, 2012, 11:23:08 AM4/12/12
to OpenNI
Hi,
I've uploaded a few days ago a small algorithm that uses the Microsoft
SDK and exports all the joint angles and coordinates data to XML or
CSV:
http://computing-technologies.com/softwares-Microsoft Kinect Joint
Angles, export Skeleton to XML, Depth data and RGB recording

I'm still developing the software, if you're interested try to see the
algorithm.

Oriol Lopez

unread,
Apr 19, 2012, 1:49:01 PM4/19/12
to OpenNI
Dan, I tried to use your example and it did good with the code
explained in http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToEuler/index.htm
Rz gives 90º, and the others 0º. I understood now what the orientation
matrix's data mean, thanks to your explanation to make the matrix for
the hips, still, I can't make it work fine.
Now the 3D model doesn't move awkwardly and all random. If I move a
leg, the model does it as well, but not quite good, it seems like it's
too heavy to move or just rotates in a wrong way. I tried to make the
angles of the rotations local, for example: RotX_LeftKnee =
RotX_LeftKnee - RotX_LeftHip - RotX_Hip
I even tried to get only the rotations of the knee, since it only
rotates around the X-axis should be easy. I assumed the rest of the
rotations as 0. But nothing again. Do you have any idea of what I'm
missing?

Oriol Lopez

unread,
Apr 19, 2012, 1:50:51 PM4/19/12
to OpenNI
phil217, thx for telling! Let me have some time to understand and get
it all together since I'm not that good with maths ^^U.

On 12 abr, 17:23, phil217 <philippesa...@gmail.com> wrote:
> Hi,
> I've uploaded a few days ago a small algorithm that uses the Microsoft
> SDK and exports all the joint angles and coordinates data to XML or
> CSV:http://computing-technologies.com/softwares-MicrosoftKinect Joint

phil217

unread,
Apr 19, 2012, 1:58:14 PM4/19/12
to OpenNI
If you need any help don't hesitate to let me know, I'll be glad to
give you some advice

Dan

unread,
Apr 20, 2012, 4:37:49 PM4/20/12
to OpenNI
Order of rotations matters, so make sure you are storing them in the
BVH the same way you are decomposing them in code.

For local rotations, you need to take the world rotation matrix for a
joint, multiply it by the inverse of its parent and then convert to
Euler angles. Performing arithmetic on the Euler angles alone will not
produce correct results.

dba

Oriol Lopez

unread,
Apr 25, 2012, 1:05:22 PM4/25/12
to OpenNI
Dan, I tried that but didn't work. The rotations are again all
random...
Just to be clear, you meant something like:
RotX_LeftElbow = Turn2Euler(LeftElbow.orientationMatrix *
Inverse(LeftShoulder.orietnationMatrix));

Could you explain why it should be done like this? I mean, what the
maths tell us for this method.

Yassir Ennazk

unread,
Apr 25, 2012, 1:18:56 PM4/25/12
to openn...@googlegroups.com
Try inversing the multiplication. Matrix multiplications are not commutative.

Try this : RotX_LeftElbow = Turn2Euler(Inverse(LeftShoulder.orietnationMatrix) * LeftElbow.orientationMatrix);

Yassir

Oriol Lopez

unread,
Apr 26, 2012, 11:23:13 AM4/26/12
to OpenNI
Nope, that's not working either :S

Yassir Ennazk

unread,
Apr 26, 2012, 11:25:40 AM4/26/12
to openn...@googlegroups.com
I see that you are affecting Turn2Euler to the rotationX.
What does Turn2Euler return ?

Rodrigo Ibañez

unread,
Apr 26, 2012, 12:01:21 PM4/26/12
to openn...@googlegroups.com
Have you read NISkeletonController from Unity Wraper?
I attach here.
I think you could take the transformations and save them.
Please let me know if you're lucky. I am interested in this too.

 
El 26 de abril de 2012 12:25, Yassir Ennazk <enn...@gmail.com> escribió:
I see that you are affecting Turn2Euler to the rotationX.
What does Turn2Euler return ?

--
You received this message because you are subscribed to the Google Groups "OpenNI" group.
To view this discussion on the web visit https://groups.google.com/d/msg/openni-dev/-/Icq-m-T1xGgJ.

To post to this group, send email to openn...@googlegroups.com.
To unsubscribe from this group, send email to openni-dev+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/openni-dev?hl=en.

NISkeletonController.cs

Oriol Lopez

unread,
Apr 27, 2012, 7:58:16 AM4/27/12
to OpenNI
After revising my code, I saw that I made some mistakes (ah... I'm so
embarrassed). At least, I could manage to make another step! Now the
model seems to mimic me, still, not as fluent as I wanted, but it's
something.
Turn2Euler was an example, it just returns you all three rotations of
a given rotationMatrix. For example, my L_knee in a T-pose has this
matrix (after being multpiplied by its parent's inverse):

| 0.99 0.00 0.14 |
| -0.01 1.00 0.07 |
| -0.14 -0.07 0.99 |

Rotations:
X: -3.81 Y: 8.24 Z: -0.09

I store the rotations in ZXY order, since I've seen in BVH Hierarchy
examples that Joint's channels are like this:
CHANNELS 3 Zrotation Xrotation Yrotation

I've found the following problems:
- When I walked towards the camera, the model didn't go forward but
backwards instead.
- If I lifted my knee so I could see it in front of me with my leg
making a 90º angle, the model would do the same but in the opposite
direction (just as if I moved my foot behind me, making that 90º angle
with my leg).
-> temporary "Solution": I tried to negate the Z position of the root
(the hips) and also, negating all X angle rotations. Now the model
moves forward if I do and lifts its knees in the right direction.
Still, movements are not so fluent, is there a way to improve this?
And by the way, is this solution a good way to do this? Perhaps I'm
overlooking something, I read somewhere in this forum that OpenNI uses
a left handed coordinate system and BVH a right handed coordinate
system, could this be the source of problems?

(the next ones are seen even with this "solution")
- Some rotations are twitching, like suddenly changing its
orientation. When I bend my back towards (like a Chinese salutation),
the legs raise from the ground, as if the model was flying or
something...
- Another problem is the arms, they don't seem to be working good. If
I pose myself as an "I-pose" (with my arms straight and my hands close
to my hips) the model does a T-pose. And if I make a T-pose the model
does an I-pose but with the hands moved forward, separating from the
waist.
I think this is because OpenNI has its initial pose as a T-pose, but
BVH has it as a I-pose. If that's the case this is going to give
another big headache.

I know that my English is not good enough to describe all this... so
'ill attach the .bvh files I'm generating. I start in a T-pose, then
lower my right arm, then my left arm (making an I-pose), then I go to
again to a T-pose and return to the I-pose (with both arms). Next, the
legs are lifted, first right, then left. Finally I bend forward and
walk towards the camera. In the file that hasn't this solution, I
don't know why the left leg turns mad though... not always happens
that (which concerns me a lot...).

I hope we can find a solution. I believe we're close!!

(animation.bvh)
http://dl.dropbox.com/u/5105047/animation.bvh
(animation(without solution).bvh)
http://dl.dropbox.com/u/5105047/animation(without%20solution).bvh
Reply all
Reply to author
Forward
0 new messages