Viewport
- class tools.manual.face_viewer.viewport.Viewport(canvas: FacesViewer, tk_edited_variable: tk.BooleanVar)
Bases:
objectHandles the display of faces and annotations in the currently viewable area of the canvas.
- Parameters:
canvas (
tkinter.Canvas) – TheFacesViewercanvastk_edited_variable (
tkinter.BooleanVar) – The variable that indicates that a face has been edited
Attributes Summary
The pixel size of each thumbnail
The hover box for the viewport.
Dynamic keyword arguments defining the color and state for the objects that make up a single face's mesh annotation based on the current user selected options.
The currently selected editor.
Methods Summary
face_from_point(point_x, point_y)Given an (x, y) point on the
Viewport, obtain the face information at that location.get_landmarks(frame_index, face_index, face, ...)Obtain the landmark points for each mesh annotation.
get_tk_face(frame_index, face_index, face)Obtain the
TKFaceobject for the given face from the cache.Check whether the active frame is going off the bottom of the viewport, if so: move it to the top of the viewport.
reset()Reset all the cached objects on a face size change.
toggle_mask(state, mask_type)Toggles the mask optional annotation on and off.
toggle_mesh(state)Toggles the mesh optional annotations on and off.
update([refresh_annotations])Update the viewport.
Attributes Documentation
- face_size
The pixel size of each thumbnail
- Type:
int
- hover_box
The hover box for the viewport.
- Type:
HoverBox
- mesh_kwargs
Dynamic keyword arguments defining the color and state for the objects that make up a single face’s mesh annotation based on the current user selected options. Values are the keyword arguments for that given type.
- Type:
dict[Literal[“polygon”, “line”], str | int]
- selected_editor
The currently selected editor.
- Type:
str
Methods Documentation
- face_from_point(point_x: int, point_y: int) ndarray
Given an (x, y) point on the
Viewport, obtain the face information at that location.- Parameters:
point_x (int) – The x position on the canvas of the point to retrieve the face for
point_y (int) – The y position on the canvas of the point to retrieve the face for
- Returns:
Array of shape (4, ) containing the (frame index, face index, x_point of top left corner, y point of top left corner) of the face at the given coordinates.
If the given coordinates are not over a face, then the frame and face indices will be -1
- Return type:
numpy.ndarray
- get_landmarks(frame_index: int, face_index: int, face: DetectedFace, top_left: list[float], refresh: bool = False) dict[T.Literal['polygon', 'line'], list[np.ndarray]]
Obtain the landmark points for each mesh annotation.
First tries to obtain the aligned landmarks from the cache. If the landmarks do not exist in the cache, or a refresh has been requested, then the landmarks are calculated from the detected face object.
- Parameters:
frame_index (int) – The frame index to obtain the face for
face_index (int) – The face index of the face within the requested frame
face (
lib.align.DetectedFace) – The detected face object to obtain landmarks fortop_left (list[float]) – The top left (x, y) points of the face’s bounding box within the viewport
refresh (bool, optional) – Whether to force a reload of the face’s aligned landmarks, even if they already exist within the cache. Default:
False
- Returns:
The key is the tkinter canvas object type for each part of the mesh annotation (polygon, line). The value is a list containing the (x, y) coordinates of each part of the mesh annotation, from the top left corner location.
- Return type:
dict
- get_tk_face(frame_index: int, face_index: int, face: DetectedFace) TKFace
Obtain the
TKFaceobject for the given face from the cache. If the face does not exist in the cache, then it is generated and added prior to returning.- Parameters:
frame_index (int) – The frame index to obtain the face for
face_index (int) – The face index of the face within the requested frame
face (
DetectedFace) – The detected face object, containing the thumbnail jpg
- Returns:
An object for displaying in the faces viewer canvas populated with the aligned mesh landmarks and face thumbnail
- Return type:
- move_active_to_top() None
Check whether the active frame is going off the bottom of the viewport, if so: move it to the top of the viewport.
- Return type:
None
- reset() None
Reset all the cached objects on a face size change.
- Return type:
None
- toggle_mask(state: Literal['hidden', 'normal'], mask_type: str) None
Toggles the mask optional annotation on and off.
- Parameters:
state (Literal["hidden", "normal"]) – Whether the mask should be displayed or hidden
mask_type (str) – The type of mask to overlay onto the face
- Return type:
None
- toggle_mesh(state: Literal['hidden', 'normal']) None
Toggles the mesh optional annotations on and off.
- Parameters:
state (Literal["hidden", "normal"]) – The state to set the mesh annotations to
- Return type:
None
- update(refresh_annotations: bool = False) None
Update the viewport.
- Parameters:
refresh_annotations (bool, optional) –
Trueif mesh annotations should be re-calculated otherwiseFalse. Default:Falsecanvas (Obtains the objects that are currently visible. Updates the visible area of the)
annotations. (and reloads the active frame's)
- Return type:
None
- face_from_point(point_x: int, point_y: int) ndarray
Given an (x, y) point on the
Viewport, obtain the face information at that location.- Parameters:
point_x (int) – The x position on the canvas of the point to retrieve the face for
point_y (int) – The y position on the canvas of the point to retrieve the face for
- Returns:
Array of shape (4, ) containing the (frame index, face index, x_point of top left corner, y point of top left corner) of the face at the given coordinates.
If the given coordinates are not over a face, then the frame and face indices will be -1
- Return type:
numpy.ndarray
- property face_size: int
The pixel size of each thumbnail
- Type:
int
- get_landmarks(frame_index: int, face_index: int, face: DetectedFace, top_left: list[float], refresh: bool = False) dict[T.Literal['polygon', 'line'], list[np.ndarray]]
Obtain the landmark points for each mesh annotation.
First tries to obtain the aligned landmarks from the cache. If the landmarks do not exist in the cache, or a refresh has been requested, then the landmarks are calculated from the detected face object.
- Parameters:
frame_index (int) – The frame index to obtain the face for
face_index (int) – The face index of the face within the requested frame
face (
lib.align.DetectedFace) – The detected face object to obtain landmarks fortop_left (list[float]) – The top left (x, y) points of the face’s bounding box within the viewport
refresh (bool, optional) – Whether to force a reload of the face’s aligned landmarks, even if they already exist within the cache. Default:
False
- Returns:
The key is the tkinter canvas object type for each part of the mesh annotation (polygon, line). The value is a list containing the (x, y) coordinates of each part of the mesh annotation, from the top left corner location.
- Return type:
dict
- get_tk_face(frame_index: int, face_index: int, face: DetectedFace) TKFace
Obtain the
TKFaceobject for the given face from the cache. If the face does not exist in the cache, then it is generated and added prior to returning.- Parameters:
frame_index (int) – The frame index to obtain the face for
face_index (int) – The face index of the face within the requested frame
face (
DetectedFace) – The detected face object, containing the thumbnail jpg
- Returns:
An object for displaying in the faces viewer canvas populated with the aligned mesh landmarks and face thumbnail
- Return type:
- property mesh_kwargs: dict[Literal['polygon', 'line'], dict[str, Any]]
Dynamic keyword arguments defining the color and state for the objects that make up a single face’s mesh annotation based on the current user selected options. Values are the keyword arguments for that given type.
- Type:
dict[Literal[“polygon”, “line”], str | int]
- move_active_to_top() None
Check whether the active frame is going off the bottom of the viewport, if so: move it to the top of the viewport.
- Return type:
None
- reset() None
Reset all the cached objects on a face size change.
- Return type:
None
- property selected_editor: str
The currently selected editor.
- Type:
str
- toggle_mask(state: Literal['hidden', 'normal'], mask_type: str) None
Toggles the mask optional annotation on and off.
- Parameters:
state (Literal["hidden", "normal"]) – Whether the mask should be displayed or hidden
mask_type (str) – The type of mask to overlay onto the face
- Return type:
None
- toggle_mesh(state: Literal['hidden', 'normal']) None
Toggles the mesh optional annotations on and off.
- Parameters:
state (Literal["hidden", "normal"]) – The state to set the mesh annotations to
- Return type:
None
- update(refresh_annotations: bool = False) None
Update the viewport.
- Parameters:
refresh_annotations (bool, optional) –
Trueif mesh annotations should be re-calculated otherwiseFalse. Default:Falsecanvas (Obtains the objects that are currently visible. Updates the visible area of the)
annotations. (and reloads the active frame's)
- Return type:
None