Recycler

class tools.manual.face_viewer.viewport.Recycler(canvas: FacesViewer)

Bases: object

Tkinter can slow down when constantly creating new objects.

This class delivers recycled objects, if stale objects are available, otherwise creates a new object

:param FacesViewer: The canvas that holds the faces display

Methods Summary

get_image(coordinates)

Obtain a recycled or new image object ID

get_mesh(face)

Get the mesh annotation for the landmarks.

recycle_assets(asset_ids)

Recycle assets that are no longer required

Methods Documentation

Parameters:

canvas (FacesViewer)

get_image(coordinates: tuple[float | int, float | int]) int

Obtain a recycled or new image object ID

Parameters:

coordinates (tuple[float | int, float | int]) – The co-ordinates that the image should be displayed at

Returns:

The canvas object id for the created image

Return type:

int

get_mesh(face: DetectedFace) dict[T.Literal['polygon', 'line'], list[int]]

Get the mesh annotation for the landmarks. This is made up of a series of polygons or lines, depending on which part of the face is being annotated. Creates a new series of objects, or pulls existing objects from the recycled objects pool if they are available.

Parameters:

face (DetectedFace) – The detected face object to obrain the mesh for

Returns:

The dictionary of line and polygon tkinter canvas object ids for the mesh annotation

Return type:

dict[Literal[“polygon”, “line”], list[int]]

recycle_assets(asset_ids: list[int]) None

Recycle assets that are no longer required

Parameters:

asset_ids (list[int]) – The IDs of the assets to be recycled

Return type:

None

get_image(coordinates: tuple[float | int, float | int]) int

Obtain a recycled or new image object ID

Parameters:

coordinates (tuple[float | int, float | int]) – The co-ordinates that the image should be displayed at

Returns:

The canvas object id for the created image

Return type:

int

get_mesh(face: DetectedFace) dict[T.Literal['polygon', 'line'], list[int]]

Get the mesh annotation for the landmarks. This is made up of a series of polygons or lines, depending on which part of the face is being annotated. Creates a new series of objects, or pulls existing objects from the recycled objects pool if they are available.

Parameters:

face (DetectedFace) – The detected face object to obrain the mesh for

Returns:

The dictionary of line and polygon tkinter canvas object ids for the mesh annotation

Return type:

dict[Literal[“polygon”, “line”], list[int]]

recycle_assets(asset_ids: list[int]) None

Recycle assets that are no longer required

Parameters:

asset_ids (list[int]) – The IDs of the assets to be recycled

Return type:

None