From d8a99939069d9d9440a509e15af21feccb185ed4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Agust=C3=ADn=20Castro?= Date: Mon, 26 Feb 2024 18:14:51 -0300 Subject: [PATCH] Get default scale in AbsolutePaths depending if coord_transform is passed --- demos/camera_motion/src/demo.py | 4 ++-- norfair/drawing/path.py | 15 ++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/demos/camera_motion/src/demo.py b/demos/camera_motion/src/demo.py index f0a0c791..07cd96b5 100644 --- a/demos/camera_motion/src/demo.py +++ b/demos/camera_motion/src/demo.py @@ -160,12 +160,12 @@ def run(): "--draw-paths", dest="draw_paths", action="store_true", - help="Pass this flag to draw the paths of the objects (SLOW)", + help="Pass this flag to draw the paths of the objects", ) parser.add_argument( "--path-drawer-scale", type=int, - default=3, + default=None, help="Canvas (background) scale relative to frame size for the AbsolutePath drawer", ) parser.add_argument( diff --git a/norfair/drawing/path.py b/norfair/drawing/path.py index b871389c..83a8917a 100644 --- a/norfair/drawing/path.py +++ b/norfair/drawing/path.py @@ -178,7 +178,7 @@ class AbsolutePaths: def __init__( self, - scale: float = 3, + scale: float = None, attenuation: float = 0.05, get_points_to_draw: Optional[Callable[[np.array], np.array]] = None, thickness: Optional[int] = None, @@ -236,6 +236,13 @@ def draw(self, frame, tracked_objects, coord_transform=None): # initialize background if necessary if self._background is None: + if self.scale is None: + # set the default scale, depending if coord_transform is provided or not + if coord_transform is None: + self.scale = 1 + else: + self.scale = 3 + original_size = ( frame.shape[1], frame.shape[0], @@ -318,10 +325,8 @@ def draw(self, frame, tracked_objects, coord_transform=None): ) else: background_size_frame = self._background[ - self.top_left[1] :, self.top_left[0] : - ] - background_size_frame = background_size_frame[ - : frame.shape[0], : frame.shape[1] + self.top_left[1] : self.top_left[1] + frame.shape[0], + self.top_left[0] : self.top_left[0] + frame.shape[1], ] frame = cv2.addWeighted(