kornia.geometry.pose#
NamedPose holds an Se2 or Se3 pose
together with the names of its source and destination frames. A pose b_from_a maps points in frame a to
frame b, and c_from_b * b_from_a is c_from_a: a composition whose frames do not chain raises instead of
returning a wrong pose.
- class kornia.geometry.pose.NamedPose(dst_from_src, frame_src=None, frame_dst=None)[source]#
Hold an SE(2) or SE(3) pose with the names of its two frames, which composition checks.
b_from_a = NamedPose(pose, frame_src="a", frame_dst="b")wraps anSe3orSe2pose that maps frameato frameb;b_from_a.transform_points(points)maps points fromatob, andc_from_b * b_from_acomposes two poses intoc_from_aafter checking that the frames chain. An unbatchedSe3maps(3,)or(N, 3), and a batch ofBmaps(B, 3), one point per pose (a batch of one also maps(N, 3)); an unbatchedSe2maps(2,)or(N, 2), and a batch ofBmaps(B, 2). Other layouts, such as a batch of poses with a point set(B, N, 3), raiseValueError. Build one from a rotation and a translation withfrom_rt(), or from a3 x 3or4 x 4matrix withfrom_matrix(). For a pose without frame names, use the Lie group classes directly; for4 x 4matrices,compose_transformations().- Convention:
NamedPose(pose, frame_src="1", frame_dst="0")istrans_01in the notation ofrelative_transformation(), for anSe2and anSe3pose alike.The matrix of
c_from_b * b_from_aisc_from_b.pose.matrix() @ b_from_a.pose.matrix(). The left operand’sframe_srcmust equal the right operand’sframe_dst, otherwise*raisesValueError;inverse()inverts the pose and swaps the frame names.The pose must be an
Se2or anSe3: anSo3,So2,Quaternionor tensor is rejected at construction (usefrom_rt()orfrom_matrix()to build a pose from one), and*raisesTypeErrorfor a right operand that is not aNamedPoseor holds the other group.
See also
Se3: the 3D rigid pose it wraps, without frame names.Se2: the 2D rigid pose it wraps, without frame names.relative_transformation(): the relative pose of two4 x 4matrices.
Example
>>> b_from_a = NamedPose(Se3.identity(), frame_src="frame_a", frame_dst="frame_b") >>> b_from_a NamedPose(dst_from_src=rotation: tensor([1., 0., 0., 0.]) translation: Parameter containing: tensor([0., 0., 0.], requires_grad=True), frame_src: frame_a -> frame_dst: frame_b)
- __init__(dst_from_src, frame_src=None, frame_dst=None)[source]#
Construct NamedPose.
- Parameters:
dst_from_src (
Se2|Se3) – Pose from source frame to destination frame.frame_src (
str|None, optional) – Name of the source frame; a random unique name when omitted or empty. Default:Noneframe_dst (
str|None, optional) – Name of the destination frame; a random unique name when omitted or empty. Default:None
- Raises:
TypeCheckError – if
dst_from_srcis not anSe2or anSe3.
- __mul__(other)[source]#
Compose two NamedPoses.
- Parameters:
other (
NamedPose) – NamedPose to compose with.- Return type:
- Returns:
Composed NamedPose.
- Raises:
TypeError – if
otheris not aNamedPoseor its pose is not of the same group asself.pose.ValueError – if
self.frame_srcis notother.frame_dst.
Example
>>> b_from_a = NamedPose(Se3.identity(), frame_src="frame_a", frame_dst="frame_b") >>> c_from_b = NamedPose(Se3.identity(), frame_src="frame_b", frame_dst="frame_c") >>> c_from_b * b_from_a NamedPose(dst_from_src=rotation: tensor([1., 0., 0., 0.]) translation: tensor([0., 0., 0.], grad_fn=<AddBackward0>), frame_src: frame_a -> frame_dst: frame_c)
- classmethod from_matrix(matrix, frame_src=None, frame_dst=None)[source]#
Construct NamedPose from a matrix.
- Parameters:
- Return type:
- Returns:
NamedPose constructed from a matrix.
Example
>>> b_from_a_matrix = torch.eye(4) >>> b_from_a = NamedPose.from_matrix(b_from_a_matrix, frame_src="frame_a", frame_dst="frame_b") >>> b_from_a NamedPose(dst_from_src=rotation: tensor([1., 0., 0., 0.]) translation: Parameter containing: tensor([0., 0., 0.], requires_grad=True), frame_src: frame_a -> frame_dst: frame_b)
- classmethod from_rt(rotation, translation, frame_src=None, frame_dst=None)[source]#
Construct NamedPose from rotation and translation.
- Parameters:
rotation (
So3|So2|Tensor|Quaternion) – Rotation part of the pose.translation (
Tensor) – Translation part of the pose.frame_src (
str|None, optional) – Name of the source frame; a random unique name when omitted or empty. Default:Noneframe_dst (
str|None, optional) – Name of the destination frame; a random unique name when omitted or empty. Default:None
- Return type:
- Returns:
NamedPose constructed from rotation and translation.
Example
>>> b_from_a_rot = So3.identity() >>> b_from_a_trans = torch.tensor([1., 2., 3.]) >>> b_from_a = NamedPose.from_rt(b_from_a_rot, b_from_a_trans, frame_src="frame_a", frame_dst="frame_b") >>> b_from_a NamedPose(dst_from_src=rotation: tensor([1., 0., 0., 0.]) translation: Parameter containing: tensor([1., 2., 3.], requires_grad=True), frame_src: frame_a -> frame_dst: frame_b)
- inverse()[source]#
Inverse of the NamedPose.
- Return type:
- Returns:
Inverse of the NamedPose.
Example
>>> b_from_a = NamedPose(Se3.identity(), frame_src="frame_a", frame_dst="frame_b") >>> b_from_a.inverse() NamedPose(dst_from_src=rotation: tensor([1., -0., -0., -0.]) translation: tensor([0., 0., 0.], grad_fn=<SliceBackward0>), frame_src: frame_b -> frame_dst: frame_a)
- transform_points(points_in_src)[source]#
Transform points from source frame to destination frame.
- Parameters:
points_in_src (
Tensor) – Points in source frame.- Return type:
- Returns:
Points in destination frame.
Example
>>> b_from_a = NamedPose(Se3.identity(), frame_src="frame_a", frame_dst="frame_b") >>> b_from_a.transform_points(torch.tensor([1., 2., 3.])) tensor([1., 2., 3.], grad_fn=<AddBackward0>)