Skip to content

Utils#

print_objects_as_table(tracked_objects) #

Used for helping in debugging

Source code in norfair/utils.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
65
66
67
68
69
70
71
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
 95
 96
 97
 98
 99
100
@lru_cache(maxsize=None)
def warn_once(message):
    """
    Write a warning message only once.
    """
    warn(message)