How can I rotate 3D object which I have Rotation matrix and translation matrix python

123 Views Asked by At

I have a deep learning model which gives translation and rotation matrixes of my 3d object according to the camera as a result. I want to rotate and refine the object lets say 5 degrees on its x axis using python. what should I do?

rotation_matrix = [[ 0.99781346 -0.06608013 -0.00129879]
[ 0.00725005  0.12896627 -0.99162245]
[ 0.06569404  0.98944485  0.12916337]]

translation_matrix = [[-13.7971115]
[ -7.9274826]
[423.7128   ]]

thanks in advance

1

There are 1 best solutions below

0
On BEST ANSWER

I have found the answer. you need to import scipy

from scipy.spatial.transform import Rotation   

### first transform the matrix to euler angles
r =  Rotation.from_matrix(rotation_matrix)
angles = r.as_euler("zyx",degrees=True)

#### Modify the angles
print(angles)
angles[0] += 5

#### Then transform the new angles to rotation matrix again
r = Rotation.from_euler("zyx",angles,degrees=True)
new_rotation_matrix = new_r.as_matrix()