Skip to content
This repository was archived by the owner on Jul 26, 2020. It is now read-only.

Commit c993569

Browse files
committed
Add Homography Matrices as a type
1 parent 28bc729 commit c993569

2 files changed

Lines changed: 25 additions & 8 deletions

File tree

sb_vision/coordinates.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Types and helpers for manipulating coordinates."""
22

3-
from typing import NamedTuple, Union
3+
from typing import List, NamedTuple, Union
44

55
import numpy as np
66
from numpy import arctan2, float64, linalg
@@ -24,6 +24,18 @@ def tolist(self):
2424
return list(self)
2525

2626

27+
class HomographyMatrix(List[List[AnyFloat]]):
28+
"""
29+
2D (3x3) Transformation matrix that maps the points of one image to that of another.
30+
"""
31+
32+
__slots__ = ()
33+
34+
def tolist(self):
35+
"""Placeholder helper to ease migration within robotd."""
36+
return list(self)
37+
38+
2739
Spherical = NamedTuple('Spherical', (
2840
('rot_x', AnyFloat),
2941
('rot_y', AnyFloat),

sb_vision/tokens.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from .coordinates import (
88
Cartesian,
9+
HomographyMatrix,
910
cartesian_to_legacy_polar,
1011
cartesian_to_spherical,
1112
)
@@ -44,6 +45,13 @@ def from_apriltag_detection(
4445

4546
pixel_corners = [PixelCoordinate(*l) for l in apriltag_detection.p]
4647

48+
homography_matrix = HomographyMatrix(np.reshape(
49+
[apriltag_detection.H.data[i] for i in range(9)],
50+
(3, 3),
51+
).tolist())
52+
# The homography matrix is a 2D transformation of a unit square to the
53+
# co-ordinates of the marker in the image
54+
4755
marker_id = apriltag_detection.id
4856

4957
# *************************************************************************
@@ -54,12 +62,9 @@ def from_apriltag_detection(
5462
id=marker_id,
5563
certainty=apriltag_detection.goodness,
5664
)
57-
arr = [apriltag_detection.H.data[x] for x in range(9)]
58-
homography = np.reshape(arr, (3, 3))
59-
60-
instance.update_pixel_coords(
65+
instance.update_2D_transforms(
6166
pixel_corners=pixel_corners,
62-
homography_matrix=homography,
67+
homography_matrix=homography_matrix,
6368
)
6469

6570
# We don't set coordinates in the absence of a camera model.
@@ -81,11 +86,11 @@ def from_apriltag_detection(
8186
return instance
8287

8388
# noinspection PyAttributeOutsideInit
84-
def update_pixel_coords(
89+
def update_2D_transforms(
8590
self,
8691
*,
8792
pixel_corners: List[PixelCoordinate],
88-
homography_matrix
93+
homography_matrix: HomographyMatrix
8994
):
9095
"""Set the pixel coordinate information of the Token."""
9196

0 commit comments

Comments
 (0)