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
Run the code above in your browser using DataLab