Skip to content

Commit

Permalink
Get default scale in AbsolutePaths depending if coord_transform is pa…
Browse files Browse the repository at this point in the history
…ssed
  • Loading branch information
Agustín Castro committed Feb 26, 2024
1 parent ed273fd commit d8a9993
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions demos/camera_motion/src/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
15 changes: 10 additions & 5 deletions norfair/drawing/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit d8a9993

Please sign in to comment.