view_faces: Look at detected faces in the browser, and choose faces to...

View source: R/view_faces.R

view_facesR Documentation

Look at detected faces in the browser, and choose faces to analyse

Description

Starts a small web page from R that shows every image, or every sampled video frame, with its face boxes, and opens it in your web browser. Faces of the same person share a colour, and a People panel lists each person with the images, frames and tracks they appear in. With select = TRUE, you click faces, video tracks or people, then Send to R, and view_faces() returns the chosen faces.

Usage

view_faces(
  faces,
  select = FALSE,
  selected = NULL,
  live = TRUE,
  open = interactive(),
  dir = NULL,
  title = NULL,
  max_side = NULL,
  port = NULL,
  inline = .te_in_notebook()
)

Arguments

faces

A data frame returned by detect_faces or select_faces.

select

Logical. Let the viewer choose faces and return them. Default is FALSE.

selected

Faces to start with selected, as rows of faces (for example select_faces(faces, "largest")). Only with select = TRUE.

live

Logical. Serve the page from R (the default). FALSE only writes the folder.

open

Logical. Open the page in the web browser. Default is TRUE in an interactive session.

dir

A new or empty folder for the page. Default is a new folder in the temporary directory, which R deletes when the session ends.

title

Title shown at the top of the page.

max_side

Longest side, in pixels, of the image and frame copies in the page. Default is 1280, or 640 inside a notebook, where the copies are stored in the notebook itself. Boxes are drawn in the original pixels, whatever the size of the copies.

port

Port of the local server. Default is a free port chosen at random; set one to forward it over SSH when R runs on a remote computer.

inline

Logical. Show the page inside the notebook, below the cell, instead of in a browser tab. Default is TRUE in a Jupyter notebook (Google Colab, JupyterLab, VS Code) and FALSE elsewhere. live and open are then ignored.

Details

The page is served by R itself (with httpuv) on your own computer only (127.0.0.1), at an address with a random part that only you get. It makes no outside requests. While R waits for a selection, the console is busy; press Esc (Ctrl+C in a terminal) to stop waiting.

With live = FALSE, no server is started: the page is written as a folder that also works when opened from disk, for example after copying it from a remote computer to yours. Its Export selection button then downloads a file that read_face_selection() reads.

In a Jupyter notebook, including Google Colab, the page is shown inside the notebook, below the cell (inline = TRUE, the default there). A page served from R cannot be reached from a notebook running on another computer, so in select mode the page gives a line of R code instead: click Copy R code, paste the line into a new cell and run it, and read_face_selection() returns the chosen faces.

Images without a face are shown too when faces is a complete detect_faces result; for a subset, only images with a face in it are shown. For a video, every sampled frame is shown, and the frames are extracted again (as in face_scores), unless detect_faces kept them with save_frames = TRUE.

In select mode, clicking a face in a still image selects that face; clicking a face in a video selects its whole track; clicking a person selects every face of that person.

When R runs on a remote computer over SSH, forward the port first (the message printed by view_faces() gives the command), or use live = FALSE and copy the folder.

The page lists file names and shows the images, so share it only with people who may see them. It contains no face embeddings and no scores.

Value

With select = TRUE: the chosen rows of faces, which face_scores scores and face_selection in image_scores, image_scores_dir and video_scores accepts, or NULL if you click Cancel. Otherwise, invisibly, the page: a list with its url, its folder dir, and stop(), which stops the server. With live = FALSE, the path of the page's index.html, invisibly. With inline = TRUE, invisibly, the path of the page as one self-contained file, faces.html in dir; in select mode the chosen faces come from the copied line of code.

See Also

draw_faces for the same boxes as plots in R, select_faces to choose faces by rule, number or person.

Examples

## Not run: 
images <- system.file("extdata", c("two-people.jpg", "boris-2.png", "trump2.jpg"),
                      package = "transforEmotion")
faces <- detect_faces(images)
view_faces(faces)

# Click the faces to keep, then Send to R
chosen <- view_faces(faces, select = TRUE)
face_scores(chosen, classes = c("happy", "sad", "angry", "neutral"))

# Without a server: a folder to copy, and a file to read back
view_faces(faces, select = TRUE, live = FALSE, dir = "faces-page")
chosen <- read_face_selection("~/Downloads/selection-faces-20261011-101500.json", faces)

# In a notebook (Colab): the page appears below the cell. Click the faces,
# then Copy R code, and run the copied line in a new cell, for example
view_faces(faces, select = TRUE)
chosen <- read_face_selection("te-selection:eyJzY2hlbWEiOi...", faces)

## End(Not run)


transforEmotion documentation built on Oct. 26, 2026, 5:07 p.m.