main

Source: main.js:2


Instance Methods

loadModels()

Loads all required face-api.js models for facial detection, landmarks, recognition, and age/gender. This is called during application startup to ensure the models are cached before any webcam processing.

  • See:
    • init – the main initialization routine that invokes `loadModels` before starting the camera.
    • setStatus – updates UI status while models are being loaded.

handleError(err: Error, fallbackMessage: string)

Centralized error handling for UI actions. Logs the fallback message, the error details, updates the status UI, shows the placeholder, and records the full message in the log.

Parameters

  • err (Error) — The caught error object.
  • fallbackMessage (string) — User‑friendly message describing the context of the error.
  • See:
    • init – uses handleError for camera initialization failures.
    • toggleEffect – uses handleError when scanning or applying effects fails.

computeOverall( faceapiSection: object | null, mediapipeSection: object | null, ): 'matched' | 'eluded' | 'partial-elusion' | 'unknown'

Compute the overall field of a matchStateChanged payload.

Parameters

  • faceapiSection (object | null)
  • mediapipeSection (object | null)

Returns

  • 'matched' | 'eluded' | 'partial-elusion' | 'unknown'

buildFaceapiSaveSection(saved2d: Object): object

Build the faceapi section for a save action. After saving, the best match IS the saved face (dist ≈ 0), so we report detectionState: 'matched' unconditionally.

Parameters

  • saved2d (Object)

Returns

  • object

buildMediapipeSaveSection(saved3d: Object, id: number): object

Build the mediapipe section for a save action.

Parameters

  • saved3d (Object)
  • id (number)

Returns

  • object

init()

Initializes the application: loads the database, renders statistics, sets up the canvas, registers UI event listeners, loads models, ghostyle plugins, and starts the webcam. This is the entry point called at the end of the script.

  • See:
    • loadModels – called within init to load face-api.js models before webcam activation.
    • init(); – the function is invoked at the bottom of the script to start the app.

Static Methods

setBusy(isBusy: boolean)

Sets the busy flag for the whole UI, disabling/enabling controls during asynchronous operations.

Parameters

  • isBusy (boolean) — When true, UI controls are disabled to prevent concurrent actions.
  • See:
    • init – called during startup to manage UI state while models load.
    • loadModels – UI is set busy while models are loading.
    • toggleEffect – disables controls while an effect is being applied.