Skip to content

Point-Light Display

generate_point_light_display()

python
generate_point_light_display(input_dir, output_dir, landmark_regions = [BOTH_EYES_PATH, MOUTH_PATH])

Creates a point-light display over the specified landmark_regions.

The generate_point_light_display() function provides users the ability to generate a facial point-light display with only an input video. Facial landmark regions of interest are passed in as paths (predefined, or created using pyfame.utils.create_path()). Furthermore, point density and color can be easily manipulated via input parameters. generate_point_light_display() also provides the ability to track and display point displacement history, which can be visualized in two methods. SHOW_HISTORY_ORIGIN visualizes the displacement vectors from the current point positions to their original positions, while SHOW_HISTORY_RELATIVE visualizes the displacement vectors as their relative path of travel within some time window defined by parameter history_window_msec.

Parameters

ParameterTypeDescription
input_dirstrA path string to the directory containing files to process.
output_dirstrA path string to the directory where processed files will be output.
landmark_regionslist[list[tuple]]A list of one or more facial landmark paths. These can be predefined or manually created using pyfame.utils.create_path(), which takes a list of landmark indicies and outputs a path.
point_densityfloatA float in the range [0,1] that controls the spatial density of the points in the output point-light display.
show_historyboolA boolean flag indicating whether or not to display the history vectors.
history_modeintAn integer flag specifying the method of visualizing the history vectors; one of pyfame.SHOW_HISTORY_ORIGIN or pyfame.SHOW_HISTORY_RELATIVE
history_window_msecintThe time duration in milliseconds that the relative history vectors will visualize.
history_colortuple[int]A BGR color code specifying the display color of the history vectors.
point_colortuple[int]A BGR color code specifying the display color of the points in the output point-light display.
with_sub_dirsboolA boolean flag indicating if the input directory contains sub-directories.
min_detection_confidencefloatA confidence measure in the range [0,1], passed on to the MediaPipe FaceMesh model.
min_tracking_confidencefloatA confidence measure in the range [0,1], passed on to the MediaPipe FaceMesh model.

Returns

None

Exceptions Raised

RaisesEncountered Error
ValueErrorGiven unrecognized input parameter values.
TypeErrorGiven invalid input parameter typings.
OSErrorGiven an invalid path-string for either input_dir or output_dir.
FileReadErrorIf an error is encountered instantiating cv2.VideoCapture() or calling cv2.imRead().
FileWriteErrorIf an error is encountered instantiating cv2.VideoWriter() or calling cv2.imWrite().
UnrecognizedExtensionErrorIf the function encounters an unrecognized image or video file extension.
FaceNotFoundErrorIf the mediapipe FaceMesh model cannot identify a face in the input image or video.

Quick Example

Python
import pyfame as pf

# Define input paths
in_dir = "c:/my/path/to/input/"
out_dir = "c:/my/path/to/output/"

# Simplest call; defaults to full face PLD with no history vectors
pf.generate_point_light_display(in_dir, out_dir)

# PLD of the eyes, nose and mouth, with blue relative history vectors
pf.generate_point_light_display(
    in_dir, out_dir, landmark_regions = [pf.BOTH_EYES_PATH, pf.NOSE_PATH, pf.MOUTH_PATH],
    show_history = True, history_mode = pf.SHOW_HISTORY_RELATIVE, history_color = (255,0,0)
)