Skip to content

Utils#

print_objects_as_table(tracked_objects) #

Used for helping in debugging

Source code in norfair/utils.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
def print_objects_as_table(tracked_objects: Sequence):
    """Used for helping in debugging"""
    print()
    console = Console()
    table = Table(show_header=True, header_style="bold magenta")
    table.add_column("Id", style="yellow", justify="center")
    table.add_column("Age", justify="right")
    table.add_column("Hit Counter", justify="right")
    table.add_column("Last distance", justify="right")
    table.add_column("Init Id", justify="center")
    for obj in tracked_objects:
        table.add_row(
            str(obj.id),
            str(obj.age),
            str(obj.hit_counter),
            f"{obj.last_distance:.4f}",
            str(obj.initializing_id),
        )
    console.print(table)

get_cutout(points, image) #

Returns a rectangular cut-out from a set of points on an image

Source code in norfair/utils.py
61
62
63
64
65
66
67
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]

warn_once(message) cached #

Write a warning message only once.

Source code in norfair/utils.py
89
90
91
92
93
94
@lru_cache(maxsize=None)
def warn_once(message):
    """
    Write a warning message only once.
    """
    warn(message)