#Install r and rstudio to run the following r script.
https://www.rstudio.com/products/rstudio/download/
https://cran.rstudio.com/
# Install relevant packages
install.packages("httr")
install.packages("XML")
install.packages("stringr")
install.packages("ggplot2")
#Load relevant packages
library("httr")
library("XML")
library("stringr")
library("ggplot2")
#clear the earlier objects.
rm(list = ls())
# Define image source for your r to do analysis on
img.url = "http://images.christianpost.com/full/49973/actress-megan-fox-arrives-on-the-red-carpet-for-the-film-friends-with-kids-during-the-36th-toronto-international-film-festival-tiff-in-toronto-september-9-2011.jpg"
# Define Microsoft API URL to request data
URL.emoface = 'https://api.projectoxford.ai/emotion/v1.0/recognize'
# Define access key (access key is available via: https://www.microsoft.com/cognitive-services/en-us/emotion-api)
emotionKEY = 'xxx'
# Define image
mybody = list(url = img.url)
# Request data from Microsoft
faceEMO = POST(
url = URL.emoface,
content_type('application/json'),
add_headers(.headers = c('Ocp-Apim-Subscription-Key' = emotionKEY)),
body = mybody,
encode = 'json'
)
# Show request results (if Status=200, request is okay)
faceEMO
# Reuqest results from face analysis
megan = content(faceEMO)[[1]]
# Define results in data frame
o<-as.data.frame(as.matrix(megan$scores))
# change column names
o$V1<-as.numeric(o$V1)
colnames(o)[1] <- "Level"
o$Emotion<- rownames(o)
# Make plot of different emotions
ggplot(data=o, aes(x=Emotion, y=Level)) + geom_bar(stat="identity")
https://www.rstudio.com/products/rstudio/download/
https://cran.rstudio.com/
# Install relevant packages
install.packages("httr")
install.packages("XML")
install.packages("stringr")
install.packages("ggplot2")
#Load relevant packages
library("httr")
library("XML")
library("stringr")
library("ggplot2")
#clear the earlier objects.
rm(list = ls())
# Define image source for your r to do analysis on
img.url = "http://images.christianpost.com/full/49973/actress-megan-fox-arrives-on-the-red-carpet-for-the-film-friends-with-kids-during-the-36th-toronto-international-film-festival-tiff-in-toronto-september-9-2011.jpg"
# Define Microsoft API URL to request data
URL.emoface = 'https://api.projectoxford.ai/emotion/v1.0/recognize'
# Define access key (access key is available via: https://www.microsoft.com/cognitive-services/en-us/emotion-api)
emotionKEY = 'xxx'
# Define image
mybody = list(url = img.url)
# Request data from Microsoft
faceEMO = POST(
url = URL.emoface,
content_type('application/json'),
add_headers(.headers = c('Ocp-Apim-Subscription-Key' = emotionKEY)),
body = mybody,
encode = 'json'
)
# Show request results (if Status=200, request is okay)
faceEMO
# Reuqest results from face analysis
megan = content(faceEMO)[[1]]
# Define results in data frame
o<-as.data.frame(as.matrix(megan$scores))
# change column names
o$V1<-as.numeric(o$V1)
colnames(o)[1] <- "Level"
o$Emotion<- rownames(o)
# Make plot of different emotions
ggplot(data=o, aes(x=Emotion, y=Level)) + geom_bar(stat="identity")
No comments:
Post a Comment