Title: | Convolutional Neural Network for Face Detection |
---|---|
Description: | An open source library for face detection in images. Provides a pretrained convolutional neural network based on <https://github.com/ShiqiYu/libfacedetection> which can be used to detect faces which have size greater than 10x10 pixels. |
Authors: | Jan Wijffels [aut, cre, cph] (R wrapper), BNOSAC [cph] (R wrapper), Shiqi Yu [ctb, cph] (libfacedetection C++ code) |
Maintainer: | Jan Wijffels <[email protected]> |
License: | BSD_3_clause + file LICENSE |
Version: | 0.1 |
Built: | 2024-11-10 06:43:59 UTC |
Source: | CRAN |
Detect faces in images using using a convolutional neural network available from https://github.com/ShiqiYu/libfacedetection. The function can be used to detect faces of minimal size 10x10 pixels.
image_detect_faces(x)
image_detect_faces(x)
x |
an object of class magick-image with rgb colors. Or an rgb integer array with pixel values in the 0-255 range. |
A list with elements nr and detections.
Element nr indicates the number of faces found.
The data frame detections indicates the locations of these. This data.frame has columns x, y, width and height
as well as a columns called confidence. The values of x and y are the top left of the start of the box. This data frame also has the x and y locations of 5 face landmarks (eyes, nose and mouth ends).
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", landmarks = TRUE) ## ## You can also directly pass on the RGB array in BGR format ## without the need of having magick ## tensor <- image_data(x, channels = "rgb") tensor <- as.integer(tensor) faces <- image_detect_faces(tensor) str(faces) plot(faces, x)
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", landmarks = TRUE) ## ## You can also directly pass on the RGB array in BGR format ## without the need of having magick ## tensor <- image_data(x, channels = "rgb") tensor <- as.integer(tensor) faces <- image_detect_faces(tensor) str(faces) plot(faces, x)
Plot functionality for bounding boxes detected with image_detect_faces
## 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, ... )
## 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, ... )
x |
object of class |
image |
object of class |
border |
color of the border of the box. Defaults to red. Passed on to |
lwd |
line width of the border of the box. Defaults to 5. Passed on to |
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 |
cex |
character expension factor of the text on the box. Defaults to 2. Passed on to |
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 |
an object of class magick-image
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
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