Skip to content

Commit

Permalink
Make transformation available in the transformation getter
Browse files Browse the repository at this point in the history
  • Loading branch information
Agustín Castro committed Feb 7, 2024
1 parent 18a6baa commit 70c7b97
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions norfair/camera_motion.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def __init__(
) -> None:
self.bin_size = bin_size
self.proportion_points_used_threshold = proportion_points_used_threshold
self.data = None
self.transformation = TranslationTransformation(0)

def __call__(
self, curr_pts: np.ndarray, prev_pts: np.ndarray
Expand All @@ -119,14 +119,15 @@ def __call__(
flow_mode = unique_flows[max_index]

try:
flow_mode += self.data
flow_mode += self.transformation.movement_vector
except TypeError:
pass

current_transformation = TranslationTransformation(flow_mode)
if update_prvs:
self.data = flow_mode
self.transformation = current_transformation

return update_prvs, TranslationTransformation(flow_mode)
return update_prvs, current_transformation


#
Expand Down Expand Up @@ -204,7 +205,8 @@ def __init__(
confidence: float = 0.995,
proportion_points_used_threshold: float = 0.9,
) -> None:
self.data = None

self.transformation = HomographyTransformation(np.eye(3))
if method is None:
method = cv2.RANSAC
self.method = method
Expand All @@ -227,10 +229,7 @@ def __call__(
"The homography couldn't be computed in this frame "
"due to low amount of points"
)
if isinstance(self.data, np.ndarray):
return True, HomographyTransformation(self.data)
else:
return True, None
return True, self.transformation

homography_matrix, points_used = cv2.findHomography(
prev_pts,
Expand All @@ -246,14 +245,18 @@ def __call__(
update_prvs = proportion_points_used < self.proportion_points_used_threshold

try:
homography_matrix = homography_matrix @ self.data
homography_matrix = (
homography_matrix @ self.transformation.homography_matrix
)
except (TypeError, ValueError):
pass

current_transformation = HomographyTransformation(homography_matrix)

if update_prvs:
self.data = homography_matrix
self.transformation = current_transformation

return update_prvs, HomographyTransformation(homography_matrix)
return update_prvs, current_transformation


#
Expand Down

0 comments on commit 70c7b97

Please sign in to comment.