From 5646d08c82d4e3b8241431a127525bc1c050304b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Castro?= Date: Mon, 29 Jan 2024 15:01:58 -0300 Subject: [PATCH] Add small number whenever the third column of the transformed points is 0 --- norfair/camera_motion.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/norfair/camera_motion.py b/norfair/camera_motion.py index 937230ef..c7b32047 100644 --- a/norfair/camera_motion.py +++ b/norfair/camera_motion.py @@ -150,20 +150,21 @@ def abs_to_rel(self, points: np.ndarray): ones = np.ones((len(points), 1)) points_with_ones = np.hstack((points, ones)) points_transformed = points_with_ones @ self.homography_matrix.T - points_transformed = points_transformed / points_transformed[:, -1].reshape( + last_column = points_transformed[:, -1] + last_column[last_column == 0] = 0.0000001 + points_transformed = points_transformed / last_column.reshape( -1, 1 ) new_points_transformed = points_transformed[:, :2] - if np.isnan(new_points_transformed).any() or np.isinf(new_points_transformed).any(): - new_points_transformed = np.array([[0, 0], [0, 0]]) - return new_points_transformed def rel_to_abs(self, points: np.ndarray): ones = np.ones((len(points), 1)) points_with_ones = np.hstack((points, ones)) points_transformed = points_with_ones @ self.inverse_homography_matrix.T - points_transformed = points_transformed / points_transformed[:, -1].reshape( + last_column = points_transformed[:, -1] + last_column[last_column == 0] = 0.0000001 + points_transformed = points_transformed / last_column.reshape( -1, 1 ) return points_transformed[:, :2]