Skip to content

Commit 5484a76

Browse files
Add estimate_velocity property to TrackedObject
1 parent a1ab657 commit 5484a76

File tree

1 file changed

+38
-7
lines changed

1 file changed

+38
-7
lines changed

norfair/tracker.py

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -557,15 +557,46 @@ def reid_hit_counter_is_positive(self):
557557
return self.reid_hit_counter is None or self.reid_hit_counter >= 0
558558

559559
@property
560-
def estimate(self):
561-
positions = self.filter.x.T.flatten()[: self.dim_z].reshape(-1, self.dim_points)
560+
def estimate_velocity(self) -> np.ndarray:
561+
"""Get the velocity estimate of the object from the Kalman filter. This velocity is in the absolute coordinate system.
562+
563+
Returns
564+
-------
565+
np.ndarray
566+
An array of shape (self.num_points, self.dim_points) containing the velocity estimate of the object on each axis.
567+
"""
568+
return self.filter.x.T.flatten()[self.dim_z :].reshape(-1, self.dim_points)
562569

563-
if self.abs_to_rel is not None:
564-
return self.abs_to_rel(positions)
565-
return positions
570+
@property
571+
def estimate(self) -> np.ndarray:
572+
"""Get the position estimate of the object from the Kalman filter.
573+
574+
Returns
575+
-------
576+
np.ndarray
577+
An array of shape (self.num_points, self.dim_points) containing the position estimate of the object on each axis.
578+
"""
579+
return self.get_estimate()
566580

567-
def get_estimate(self, absolute=False):
568-
positions = self.filter.x.T.flatten()[: self.dim_z].reshape(-1, 2)
581+
def get_estimate(self, absolute=False) -> np.ndarray:
582+
"""Get the position estimate of the object from the Kalman filter in an absolute or relative format.
583+
584+
Parameters
585+
----------
586+
absolute : bool, optional
587+
If true the coordinates are returned in absolute format, by default False, by default False.
588+
589+
Returns
590+
-------
591+
np.ndarray
592+
An array of shape (self.num_points, self.dim_points) containing the position estimate of the object on each axis.
593+
594+
Raises
595+
------
596+
ValueError
597+
Alert if the coordinates are requested in absolute format but the tracker has no coordinate transformation.
598+
"""
599+
positions = self.filter.x.T.flatten()[: self.dim_z].reshape(-1, self.dim_points)
569600
if self.abs_to_rel is None:
570601
if not absolute:
571602
return positions

0 commit comments

Comments
 (0)