| view_faces | R Documentation |
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.
view_faces(
faces,
select = FALSE,
selected = NULL,
live = TRUE,
open = interactive(),
dir = NULL,
title = NULL,
max_side = NULL,
port = NULL,
inline = .te_in_notebook()
)
faces |
A data frame returned by |
select |
Logical. Let the viewer choose faces and return them.
Default is |
selected |
Faces to start with selected, as rows of |
live |
Logical. Serve the page from R (the default). |
open |
Logical. Open the page in the web browser. Default is
|
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 |
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.
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.
draw_faces for the same boxes as plots in R,
select_faces to choose faces by rule, number or person.
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.