facemotionhttps://api.pixlab.io/facemotion
Description
Output the rectangle coordinates for each detected human face and try to guess their gender, age and emotion pattern via their facial shapes.
HTTP Methods
GET, POST
Request Parameters
Required
Fields | Type | Description |
---|---|---|
img | URL | Input media URL. If you want to upload your image directly from your app, then submit a multipart/form-data POST request. |
key | String | Your PixLab API Key. You can also embed your key in the WWW-Authenticate: HTTP header and omit this parameter if you want to. |
POST Request Body (If you plan to use POST instead of a simple GET request)
Allowed Content-Type:
multipart/form-data
application/json
Use multipart/form-data if you want to upload your media file directly (refer to the sample set for a working example). If you are using JSON, then the media file must be already uploaded somewhere. Call store if you want to upload an image for example before invoking this endpoint.
Response
application/json
This command return a JSON object after each call. The fields of interest here are the emotion and the rectangle values. The following are the JSON fields returned in response body:
Fields | Type | Description |
---|---|---|
status | Integer | Status code 200 indicates success, any other code indicates failure. |
faces | Array | JSON array holding the rectangle coordinates of each detected face including age, gender and their emotion state (See below). |
error | String | Error message if status != 200. |
Each entry in the returned faces array contain the following fields:
Fields | Type | Description |
---|---|---|
rectangle | Object | Rectangle coordinates namely top, left, width, height for each detected face in the given image. |
age | Integer | Age approximation of the target face. |
gender | String | Gender based on the facial shape |
emotion | Object | Object holding state & score pair. That is, emotion state and their associated score value. The following emotion pattern are returned: anger, contempt, disgust, fear, happiness, neutral, sadness, surprise |
Python Example
import requests
import json
# Detect all human faces present in a given image and try to guess their age, gender and emotion state via their facial shapes
# Target image: Feel free to change to whatever image holding as many human faces as you want
img = 'http://www.scienceforums.com/uploads/1282315190/gallery_1625_35_9165.jpg'
req = requests.get('http://api.pixlab.io/facemotion',params={
'img': img,
'key':'PixLab_API_Key',
})
reply = req.json()
if reply['status'] != 200:
print (reply['error'])
exit();
total = len(reply['faces']) # Total detected faces
print(str(total)+" faces were detected")
# Extract each face now
for face in reply['faces']:
cord = face['rectangle']
print ('Face coordinate: width: ' + str(cord['width']) + ' height: ' + str(cord['height']) + ' x: ' + str(cord['left']) +' y: ' + str(cord['top']))
# Guess emotion
for emotion in face['emotion']:
if emotion['score'] > 0.5:
print ("Emotion - "+emotion['state']+': '+str(emotion['score']))
# Grab the age and gender
print ("Age ~: " + str(face['age']))
print ("Gender: " + str(face['gender']))
See Also
header, nsfw, sfw, ocr, facedetect, facelandmarks, crop, mogrify, facelookup, facecompare, facegenerate, screencapture