Reputation: 771
It seems that the answer to my question is pretty obvious, but unfortunately I could not figure it out, please help me!
I am trying to use the vtk library to obtain the icp transform in python.
I am running this code here: http://www.vtk.org/Wiki/VTK/Examples/Python/IterativeClosestPoints
and then
print icp.GetLandmarkTransform()
The result displays the transformation matrix among other things.
...
Elements:
-> 1 4.76975e-10 0 -7.79873e-10
-> -4.76975e-10 1 -0 1.58991e-10
-> -0 0 1 0
-> 0 0 0 1
Mode: RigidBody
...
How do I extract the transformation matrix in a numpy array? I just need the transform for a 2D data set. Is there a simpler way to do it?
Thank you in advance!
Upvotes: 3
Views: 2749
Reputation: 91
Just a helper function that I use to do the same thing.
def vtkmatrix_to_numpy(matrix):
"""
Copies the elements of a vtkMatrix4x4 into a numpy array.
:param matrix: The matrix to be copied into an array.
:type matrix: vtk.vtkMatrix4x4
:rtype: numpy.ndarray
"""
m = np.ones((4, 4))
for i in range(4):
for j in range(4):
m[i, j] = matrix.GetElement(i, j)
return m
Upvotes: 2
Reputation: 473
In general vtk matrix can be extracted as python lists:
temp = [0] * 16 #the matrix is 4x4
vtk_matrix.DeepCopy(temp, vtk_matrix)
Upvotes: 3
Reputation: 771
After asking for the help of a friend he provided me with the answer. Just posting in case someone needs it:
for i in range(3):
for j in range(4):
print icp.GetLandmarkTransform().GetMatrix().GetElement(i, j),
print
print
Upvotes: 4