# Load relevant package library(httr) # Define Microsoft API URL to request data faceURL = "http://bit.ly/2beDa6i" # Define image source img.url ="https://s-media-cache-ak0.pinimg.com/236x/de/66/64/de6664e52def974ddb729042e8d57e00.jpg" # Define access key (access key is available via: https://www.microsoft.com/cognitive-services/en-us/emotion-api) faceKEY = '75e11308wb340adfg4a039d83e756af1' # Define image mybody = list(url = img.url) # Request data from Microsoft faceResponse = POST(url = faceURL,content_type('application/json'), add_headers(.headers = c('Ocp-Apim-Subscription-Key' = faceKEY)), body = mybody,encode = 'json') # Show request results (if Status=200, request is okay) faceResponse # Reuqest results from face analysis DanielCraigFace = content(faceResponse)[[1]] # Define names > names(DanielCraigFace) [1] "faceId" "faceRectangle" "faceLandmarks" "faceAttributes" # Define face Attributes > DanielCraigFace$faceAttributes $smile [1] 0.998 $gender [1] "male" $age [1] 49.7 $facialHair $facialHair$moustache [1] 0 $facialHair$beard [1] 0 $facialHair$sideburns [1] 0
No comments:
Post a Comment