Skip to content

Commit

Permalink
Add function to cut-out rectangle from image from a set of points
Browse files Browse the repository at this point in the history
  • Loading branch information
joaqo committed Feb 12, 2021
1 parent 1b9605f commit 46ceefe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion norfair/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .drawing import *
from .tracker import Detection, Tracker
from .utils import print_objects_as_table
from .utils import print_objects_as_table, get_cutout
from .video import Video
9 changes: 9 additions & 0 deletions norfair/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,12 @@ def get_terminal_size(default: Tuple[int, int] = (80, 24)) -> Tuple[int, int]:
continue
break
return columns, lines


def get_cutout(points, image):
"""Returns a rectangular cut-out from a set of points on an image"""
max_x = int(max(points[:, 0]))
min_x = int(min(points[:, 0]))
max_y = int(max(points[:, 1]))
min_y = int(min(points[:, 1]))
return image[min_y:max_y, min_x:max_x]

0 comments on commit 46ceefe

Please sign in to comment.