Description Usage Arguments Value See Also Examples
Given a grayscale input image of a face, returns a probability distribution over emotional state. Input should be a two-dimensional strucrure (like data.frame or matrix), resizing will be attempted internally but for best performance, images should be already sized at 48x48 pixels.
1 | face_emotion(img, local.api = FALSE)
|
img |
image data |
local.api |
logical, whether use local or remote API |
List with face emotions probability pairs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | ## Example 1
img <- matrix(runif(48*48, 0, 1), nrow = 48)
emotion <- face_emotion(img)
most.possible <- sort(unlist(emotion), decreasing = TRUE)[1:2]
cat(sprintf("Detected '%s' emotion with probability %0.4f.\n",
names(most.possible)[1], most.possible[1]))
cat(sprintf("Next possible is '%s' emotion with probability %0.4f.",
names(most.possible)[2], most.possible[2]))
## Example 2
# Reads PNG file
file.face <- system.file("extdata", "face1.png", package = "indicoio")
img <- readPNG(file.face)
# Converts to grayscale
img <- 0.2126 * img[, , 1] + 0.7152 * img[, , 2] + 0.0722 * img[, , 3]
# Plots image
plot(0:1, 0:1, xlab = "", ylab = "", axes = FALSE, col = "white")
rasterImage(img, xleft = 0, ybottom = 0, xright = 1, ytop = 1)
# Detects emotion
face_emotion(img)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.