meshonline / kinect-openni-bvh-saver

This project is based on OpenNI2, NITE2, and OpenCV2, it will automatically save many skeleton animation clips to bvh files.
MIT License
206 stars 57 forks source link

About quaternion to euler rotation #2

Open milkcat0904 opened 6 years ago

milkcat0904 commented 6 years ago

hello, thx for your code, i'm doing something just similar with your project. I have encountered some problems that need your help.

I have each joint quaternion and location data and i need to get the CHANNEL of BVH file. I found that the HIERARCHY of BVH file i download from website are all the same,so i just copy HIERARCHY part and write MOTION data.

I did the following things with Pyrhon: 1.calculate relative quaternion between current joint and parent joint q_relative = q_current inverse(q_parent) 2.calculate euler rotation ZXY(my BVH file all the CHANNEL is Z-X-Y rotation) ''' y1 = 2(orientationXorientationY - orientationWorientationZ) y2 = orientationWorientationW - orientationXorientationX + orientationY+orientationY - orientationZ*orientationZ

x = 2*(orientationY*orientationZ + orientationW*orientationX)
x = +1 if x > +1 else x
x = -1 if x < -1 else x

z1 = 2*(orientationX*orientationZ - orientationW*orientationY)
z2 = orientationW*orientationW - orientationX*orientationX - orientationY+orientationY + orientationZ*orientationZ

rotationZ = math.degrees(math.atan2(z1, z2))
rotationX = math.degrees(math.asin(x))
rotationY = math.degrees(math.atan2(y1, y2))

euler_rotation = [rotationZ, rotationX, rotationY]

'''

After the visualization, the movement is wrong. This problem has been bothering me for a long time, I need your help.

meshonline commented 6 years ago

Hi,

I’m not familiar with Python, so I can not help with your question.

Art

在 2018年8月13日,下午3:51,catidog notifications@github.com 写道:

hello, thx for your code, i'm doing something just similar with your project. I have encountered some problems that need your help.

I have each joint quaternion and location data and i need to get the CHANNEL of BVH file. I found that the HIERARCHY of BVH file i download from website are all the same,so i just copy HIERARCHY part and write MOTION data.

I did the following things with Pyrhon: 1.calculate relative quaternion between current joint and parent joint q_relative = q_current inverse(q_parent) 2.calculate euler rotation ZXY(my BVH file all the CHANNEL is Z-X-Y rotation) ''' y1 = 2(orientationXorientationY - orientationWorientationZ) y2 = orientationWorientationW - orientationXorientationX + orientationY+orientationY - orientationZ*orientationZ

x = 2(orientationYorientationZ + orientationW*orientationX) x = +1 if x > +1 else x x = -1 if x < -1 else x

z1 = 2(orientationXorientationZ - orientationWorientationY) z2 = orientationWorientationW - orientationXorientationX - orientationY+orientationY + orientationZorientationZ

rotationZ = math.degrees(math.atan2(z1, z2)) rotationX = math.degrees(math.asin(x)) rotationY = math.degrees(math.atan2(y1, y2))

euler_rotation = [rotationZ, rotationX, rotationY] '''

After the visualization, the movement is wrong. This problem has been bothering me for a long time, I need your help.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/meshonline/kinect-openni-bvh-saver/issues/2, or mute the thread https://github.com/notifications/unsubscribe-auth/ANM5wxrYFeTBZpVAf3ooK-ycVMYsB6ZKks5uQTAVgaJpZM4V6CcV.

c4b4d4 commented 5 years ago

Hi, did you manage to solve this?

meshonline commented 5 years ago

I just realized that you can read the source code of the BVH importer of Blender, if you have confirmed that your code is right, there is another thing you may forget to setup, you need to setup the rotation mode for each joint from 'Quaternion(WXYZ)' to 'ZXY Euler’ in pose mode.

在 2019年1月23日,上午12:44,Carlos Cabada notifications@github.com 写道:

Hi, did you manage to solve this?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/meshonline/kinect-openni-bvh-saver/issues/2#issuecomment-456471110, or mute the thread https://github.com/notifications/unsubscribe-auth/ANM5w-QIFvJQ849RAO0SXNCWUPrKA6cGks5vFz_mgaJpZM4V6CcV.

c4b4d4 commented 5 years ago

I need to do everything in real-time, not over recorded files. I'm doing a virtual character control but the rotations seem to be so wrongly done.

This is what I'm facing: Stack Overflow Question