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

Commit 6c1a3fa

Browse files
committed
re-add Homography Matrices
1 parent 70a377f commit 6c1a3fa

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

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: 19 additions & 5 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
)
@@ -48,6 +49,13 @@ def from_apriltag_detection(
4849

4950
pixel_corners = [PixelCoordinate(*l) for l in apriltag_detection.p]
5051

52+
homography_matrix = HomographyMatrix(np.reshape(
53+
[apriltag_detection.H.data[i] for i in range(9)],
54+
(3, 3),
55+
).tolist())
56+
# The homography matrix is a 2D transformation of a unit square to the
57+
# co-ordinates of the marker in the image
58+
5159
marker_id = apriltag_detection.id
5260

5361
# *************************************************************************
@@ -59,7 +67,10 @@ def from_apriltag_detection(
5967
certainty=apriltag_detection.goodness,
6068
)
6169

62-
instance.update_pixel_coords(pixel_corners=pixel_corners)
70+
instance.update_2D_transforms(
71+
pixel_corners=pixel_corners,
72+
homography_matrix=homography_matrix,
73+
)
6374

6475
# We don't set coordinates in the absence of a camera model.
6576
if camera_model:
@@ -80,10 +91,11 @@ def from_apriltag_detection(
8091
return instance
8192

8293
# noinspection PyAttributeOutsideInit
83-
def update_pixel_coords(
84-
self,
85-
*,
86-
pixel_corners: List[PixelCoordinate]
94+
def update_2D_transforms(
95+
self,
96+
*,
97+
pixel_corners: List[PixelCoordinate],
98+
homography_matrix: HomographyMatrix,
8799
):
88100
"""Set the pixel coordinate information of the Token."""
89101
# The pixel_corners value we expose is in clockwise order starting with
@@ -95,6 +107,8 @@ def update_pixel_coords(
95107
# centre of marker: average the corners
96108
self.pixel_centre = PixelCoordinate(*np.average(pixel_corners, axis=0))
97109

110+
self.homography_matrix = homography_matrix
111+
98112
# noinspection PyAttributeOutsideInit
99113
def update_3D_transforms(
100114
self,

0 commit comments

Comments
 (0)