plot.libfacedetection {image.libfacedetection}R Documentation

Plot detected faces

Description

Plot functionality for bounding boxes detected with image_detect_faces

Usage

## S3 method for class 'libfacedetection'
plot(
  x,
  image,
  border = "red",
  lwd = 5,
  only_box = FALSE,
  col = "red",
  cex = 2,
  landmarks = FALSE,
  col_landmarks = "black",
  cex_landmarks = 1,
  pch_landmarks = 20,
  ...
)

Arguments

x

object of class libfacedetection as returned by image_detect_faces

image

object of class magick-image which was used to construct x

border

color of the border of the box. Defaults to red. Passed on to rect

lwd

line width of the border of the box. Defaults to 5. Passed on to rect

only_box

logical indicating to draw only the box and not the text on top of it. Defaults to FALSE.

col

color of the text on the box. Defaults to red. Passed on to text

cex

character expension factor of the text on the box. Defaults to 2. Passed on to text

landmarks

logical indicating to plot the landmarks as points. Defaults to FALSE.

col_landmarks

color of the point of the landmarks. Defaults to black.

cex_landmarks

cex of the point of the landmarks. Defaults to 1.

pch_landmarks

pch of the point of the landmarks. Defaults to 20.

...

other parameters passed on to rect

Value

an object of class magick-image

Examples

library(magick)
path <- system.file(package="image.libfacedetection", "images", "handshake.jpg")
x <- image_read(path)
x
faces <- image_detect_faces(x)
faces
plot(faces, x, border = "red", lwd = 7, col = "white")
plot(faces, x, border = "red", lwd = 7, col = "white", landmarks = TRUE, 
     col_landmarks = "purple", cex_landmarks = 2, pch_landmarks = 4)

## show one detected face
face <- head(faces$detections, 1)
image_crop(x, geometry_area(x = face$x, y = face$y, 
                            width = face$width, height = face$height))
## show all detected faces
boxcontent <- lapply(seq_len(faces$nr), FUN=function(i){
  face <- faces$detections[i, ]
  image_crop(x, geometry_area(x = face$x, y = face$y, 
                              width = face$width, height = face$height))
})
boxcontent <- do.call(c, boxcontent)
boxcontent

[Package image.libfacedetection version 0.1 Index]