face++ 识别 皮肤问题

Face Analyze API

版本

3.0

描述

传入在 Detect API 检测出的人脸标识 face_token,分析得出人脸关键点,人脸属性信息。一次调用最多支持分析 5 个人脸。

调用URL

https://api-cn.faceplusplus.com/facepp/v3/face/analyze

调用方法

POST

权限

所有 API Key 都可以调用本 API。

请求参数

是否必选

参数名

类型

参数说明

必选

api_key

String

调用此 API 的 API Key

必选

api_secret

String

调用此 API 的 API Secret

必选

face_tokens

String

一个字符串,由一个或多个人脸标识组成,用逗号分隔。最多支持 5 个 face_token。

必选(至少使用一项)

return_landmark

Int

是否检测并返回人脸关键点。合法值为:

2 检测。返回 106 个人脸关键点。
1

检测。返回 83 个人脸关键点。

0

不检测

注:本参数默认值为 0

return_attributes

String

是否检测并返回根据人脸特征判断出的年龄、性别、情绪等属性。合法值为: 

none

不检测属性

  • gender
  • age
  • smiling
  • headpose
  • facequality
  • blur
  • eyestatus
  • emotion
  • ethnicity
  • beauty
  • mouthstatus
  • eyegaze
  • skinstatus

希望检测并返回的属性。

需要将属性组成一个用逗号分隔的字符串,属性之间的顺序没有要求。

关于各属性的详细描述,参见下文“返回值”说明的 "attributes" 部分。

注:由于提供了 eyestatus,所以 glass 参数将被移除(计划时间 2017-9-30),请尽快修改程序使用 eyestatus

注:本参数默认值为 none

返回值说明

字段

类型

说明

request_id String 用于区分每一次请求的唯一的字符串。

faces

Array

经过分析的人脸数组

注:如果没有检测出人脸则为空数组

time_used

Int

整个请求所花费的时间,单位为毫秒。

error_message

String

当请求失败时才会返回此字符串,具体返回内容见后续错误信息章节。否则此字段不存在。

faces 数组中单个元素的结构

字段

类型

说明

face_token

String

人脸的标识

face_rectangle

Object

人脸矩形框的位置,包括以下属性。每个属性的值都是整数:

  • top:矩形框左上角像素点的纵坐标
  • left:矩形框左上角像素点的横坐标
  • width:矩形框的宽度
  • height:矩形框的高度

landmark

Object

人脸的关键点坐标数组。

当传入的 landmark 参数值为 1 时,返回 83 个关键点坐标数组。

当传入的 landmark 参数值为 2 时,返回 106 个关键点坐标数组。

关于 83 个或 106 个关键点坐标的详细说明与图示,请分别参考文档:《人脸关键点 Landmark 说明(83 点)》、《人脸关键点 Landmark 说明(106 点)

attributes

Object

人脸属性特征,具体包含的信息见下表。

attributes 中包含的元素说明

skinstatus

Object

面部特征识别结果,包括以下字段。每个字段的值都是一个浮点数,范围 [0,100],小数点后 3 位有效数字。每个字段的返回值越大,则该字段代表的状态的置信度越高。

  • health:健康
  • stain:色斑
  • acne:青春痘
  • dark_circle:黑眼圈

代码测试:

#coding=utf8
import cv2
import cv2.cv as cv
import requests
import json
import time

i=0
 
capture = cv.CaptureFromCAM(0)              
  
while True:  
    img = cv.QueryFrame(capture)
    cv.ShowImage("camera",img)  
    key = cv.WaitKey(10)  
    if i==3:  
        break  
    if i < 3:   
        filename = "face.jpg"  
        cv.SaveImage(filename,img)
        print "图片截取成功"
        i+=1
        print(time.time())

        
del(capture) 
cv.DestroyWindow("camera")
 
url = 'https://api-cn.faceplusplus.com/facepp/v3/search'
payload = {'api_key': "19dI6tJnwhSoAFodyZA2yIucv1npQcO_",
           'api_secret': "DatyybLlcmJyjUZhykGXszZh0tIpQ45x",
           'faceset_token':'f1d4de7b23524374631cff08af33eea5',
           }
files = {'image_file':open('face.jpg', 'rb')}
r = requests.post(url,files=files,data=payload)
data=json.loads(r.text)
print r.text
if data["results"][0]["face_token"] == "bad2eabbb7ae3c619afd54ee4a081808" and data["results"][0]["confidence"]>=data["thresholds"]["1e-5"]:
    print'\n广州美哒-Jack Jiang'
elif data["results"][0]["face_token"] == "c116a106c02f6ffd8606408fe2fb5def"and data["results"][0]["confidence"]>=data["thresholds"]["1e-5"]:
    print'\n广州美哒-Lena'
else:
    print '\n不是我们公司的人员'

url = 'https://api-cn.faceplusplus.com/facepp/v3/face/analyze'
payload = {'api_key': "19dI6tJnwhSoAFodyZA2yIucv1npQcO_",
           'api_secret': "DatyybLlcmJyjUZhykGXszZh0tIpQ45x",
           'face_tokens':data["faces"][0]["face_token"],
           'return_landmark': 2,
           'return_attributes':'gender,age,smiling,headpose,facequality,blur,eyestatus,emotion,ethnicity,beauty,mouthstatus,eyegaze,skinstatus',
}

files = {'image_file':open('face.jpg', 'rb')}
r = requests.post(url,files=files,data=payload)
data=json.loads(r.text)
print r.text

测试结果:

root@01ab7d0c67f7:/home/test# python face++_analyze.py
libudev: udev_has_devtmpfs: name_to_handle_at on /dev: Operation not permitted
图片截取成功
1536937648.77
图片截取成功
1536937648.98
图片截取成功
1536937649.11
{"image_id": "qQH9RMqY4DdcAdTHYORTdA==", "faces": [{"face_rectangle": {"width": 473, "top": -186, "left": 252, "height": 473}, "face_token": "e86a894266b8fce192475a23df06d350"}], "time_used": 583, "thresholds": {"1e-3": 62.327, "1e-5": 73.975, "1e-4": 69.101}, "request_id": "1536937649,75b768fb-136b-40ed-95ea-6e784e3bb91d", "results": [{"confidence": 54.295, "user_id": "", "face_token": "bad2eabbb7ae3c619afd54ee4a081808"}]}

不是我们公司的人员
{"time_used": 466, "request_id": "1536937650,cb5e0dd9-11d9-4899-a971-6dc9ad57933b", "faces": [{"landmark": {"contour_chin": {"y": 501, "x": 175}, "left_eye_upper_left_quarter": {"y": 212, "x": 89}, "mouth_lower_lip_right_contour1": {"y": 391, "x": 203}, "left_eye_bottom": {"y": 233, "x": 106}, "mouth_lower_lip_right_contour2": {"y": 406, "x": 216}, "contour_left7": {"y": 339, "x": 40}, "contour_left6": {"y": 316, "x": 37}, "contour_left5": {"y": 294, "x": 36}, "contour_left4": {"y": 272, "x": 36}, "contour_left3": {"y": 250, "x": 38}, "contour_left2": {"y": 227, "x": 40}, "contour_left1": {"y": 205, "x": 44}, "left_eye_lower_left_quarter": {"y": 230, "x": 89}, "contour_right1": {"y": 210, "x": 380}, "contour_right3": {"y": 262, "x": 382}, "contour_right2": {"y": 236, "x": 381}, "contour_right5": {"y": 313, "x": 380}, "contour_right4": {"y": 287, "x": 381}, "contour_right7": {"y": 364, "x": 374}, "left_eyebrow_left_corner": {"y": 189, "x": 47}, "right_eye_right_corner": {"y": 226, "x": 301}, "nose_bridge1": {"y": 215, "x": 180}, "nose_bridge3": {"y": 266, "x": 171}, "nose_bridge2": {"y": 240, "x": 175}, "right_eyebrow_upper_left_corner": {"y": 182, "x": 209}, "mouth_upper_lip_right_contour4": {"y": 391, "x": 204}, "mouth_upper_lip_right_contour1": {"y": 364, "x": 188}, "right_eye_left_corner": {"y": 229, "x": 232}, "left_eyebrow_upper_right_corner": {"y": 180, "x": 152}, "left_eyebrow_upper_middle": {"y": 165, "x": 97}, "mouth_lower_lip_right_contour3": {"y": 412, "x": 196}, "nose_left_contour3": {"y": 317, "x": 127}, "mouth_lower_lip_bottom": {"y": 413, "x": 173}, "mouth_upper_lip_right_contour2": {"y": 378, "x": 214}, "left_eye_top": {"y": 208, "x": 108}, "nose_left_contour1": {"y": 231, "x": 155}, "mouth_upper_lip_bottom": {"y": 388, "x": 172}, "mouth_upper_lip_left_contour2": {"y": 378, "x": 134}, "mouth_upper_lip_top": {"y": 368, "x": 172}, "mouth_upper_lip_left_contour1": {"y": 364, "x": 156}, "mouth_upper_lip_left_contour4": {"y": 390, "x": 144}, "right_eye_top": {"y": 209, "x": 264}, "mouth_upper_lip_right_contour3": {"y": 396, "x": 226}, "right_eye_bottom": {"y": 233, "x": 266}, "right_eyebrow_lower_left_corner": {"y": 197, "x": 211}, "mouth_left_corner": {"y": 397, "x": 116}, "nose_middle_contour": {"y": 332, "x": 171}, "right_eye_lower_right_quarter": {"y": 231, "x": 284}, "right_eyebrow_lower_right_quarter": {"y": 191, "x": 299}, "contour_right9": {"y": 414, "x": 359}, "mouth_right_corner": {"y": 398, "x": 235}, "right_eye_lower_left_quarter": {"y": 232, "x": 248}, "right_eye_center": {"y": 220, "x": 266}, "left_eye_upper_right_quarter": {"y": 214, "x": 126}, "right_eyebrow_lower_left_quarter": {"y": 190, "x": 240}, "left_eye_pupil": {"y": 219, "x": 109}, "contour_right8": {"y": 389, "x": 368}, "contour_left13": {"y": 464, "x": 87}, "left_eyebrow_lower_right_quarter": {"y": 186, "x": 123}, "left_eye_right_corner": {"y": 229, "x": 139}, "left_eyebrow_lower_right_corner": {"y": 193, "x": 150}, "mouth_upper_lip_left_contour3": {"y": 396, "x": 125}, "left_eyebrow_lower_left_quarter": {"y": 185, "x": 71}, "mouth_lower_lip_left_contour1": {"y": 390, "x": 145}, "mouth_lower_lip_left_contour3": {"y": 411, "x": 151}, "mouth_lower_lip_left_contour2": {"y": 405, "x": 133}, "contour_left9": {"y": 385, "x": 46}, "left_eye_lower_right_quarter": {"y": 231, "x": 123}, "contour_right6": {"y": 338, "x": 378}, "nose_tip": {"y": 291, "x": 167}, "right_eyebrow_upper_middle": {"y": 168, "x": 270}, "right_eyebrow_lower_middle": {"y": 188, "x": 270}, "left_eye_center": {"y": 219, "x": 109}, "right_eyebrow_upper_left_quarter": {"y": 172, "x": 237}, "right_eyebrow_right_corner": {"y": 196, "x": 327}, "right_eyebrow_upper_right_quarter": {"y": 174, "x": 302}, "contour_left16": {"y": 497, "x": 149}, "contour_left15": {"y": 489, "x": 126}, "contour_left14": {"y": 478, "x": 105}, "left_eyebrow_upper_right_quarter": {"y": 170, "x": 126}, "contour_left12": {"y": 448, "x": 72}, "contour_left11": {"y": 429, "x": 60}, "contour_left10": {"y": 408, "x": 52}, "left_eyebrow_lower_middle": {"y": 184, "x": 97}, "left_eyebrow_upper_left_quarter": {"y": 169, "x": 69}, "right_eye_upper_right_quarter": {"y": 214, "x": 284}, "nose_right_contour4": {"y": 327, "x": 207}, "nose_right_contour5": {"y": 329, "x": 189}, "nose_left_contour4": {"y": 324, "x": 141}, "nose_left_contour5": {"y": 327, "x": 155}, "nose_left_contour2": {"y": 288, "x": 139}, "nose_right_contour1": {"y": 232, "x": 207}, "nose_right_contour2": {"y": 290, "x": 214}, "nose_right_contour3": {"y": 321, "x": 224}, "left_eye_left_corner": {"y": 223, "x": 75}, "contour_right15": {"y": 498, "x": 233}, "contour_right14": {"y": 493, "x": 260}, "contour_right16": {"y": 501, "x": 204}, "contour_right11": {"y": 456, "x": 330}, "contour_right10": {"y": 436, "x": 347}, "contour_right13": {"y": 484, "x": 286}, "contour_right12": {"y": 472, "x": 310}, "contour_left8": {"y": 362, "x": 42}, "mouth_lower_lip_top": {"y": 389, "x": 173}, "right_eye_upper_left_quarter": {"y": 215, "x": 246}, "right_eye_pupil": {"y": 220, "x": 266}}, "attributes": {"emotion": {"sadness": 0.007, "neutral": 99.986, "disgust": 0.0, "anger": 0.0, "surprise": 0.004, "fear": 0.0, "happiness": 0.001}, "beauty": {"female_score": 57.238, "male_score": 56.396}, "gender": {"value": "Male"}, "age": {"value": 32}, "mouthstatus": {"close": 100.0, "surgical_mask_or_respirator": 0.0, "open": 0.0, "other_occlusion": 0.0}, "glass": {"value": "None"}, "skinstatus": {"dark_circle": 3.071, "stain": 95.947, "acne": 98.685, "health": 0.981}, "headpose": {"yaw_angle": 8.504397, "pitch_angle": -2.4095652, "roll_angle": -1.6887827}, "blur": {"blurness": {"threshold": 50.0, "value": 0.096}, "motionblur": {"threshold": 50.0, "value": 0.096}, "gaussianblur": {"threshold": 50.0, "value": 0.096}}, "smile": {"threshold": 50.0, "value": 0.003}, "eyestatus": {"left_eye_status": {"normal_glass_eye_open": 0.137, "no_glass_eye_close": 0.0, "occlusion": 0.001, "no_glass_eye_open": 99.862, "normal_glass_eye_close": 0.0, "dark_glasses": 0.0}, "right_eye_status": {"normal_glass_eye_open": 0.005, "no_glass_eye_close": 0.0, "occlusion": 0.0, "no_glass_eye_open": 99.995, "normal_glass_eye_close": 0.0, "dark_glasses": 0.0}}, "facequality": {"threshold": 70.1, "value": 85.438}, "ethnicity": {"value": "ASIAN"}, "eyegaze": {"right_eye_gaze": {"position_x_coordinate": 0.505, "vector_z_component": 0.986, "vector_x_component": 0.165, "vector_y_component": 0.013, "position_y_coordinate": 0.473}, "left_eye_gaze": {"position_x_coordinate": 0.544, "vector_z_component": 0.974, "vector_x_component": 0.225, "vector_y_component": 0.014, "position_y_coordinate": 0.415}}}, "face_rectangle": {"width": 347, "top": 162, "left": 33, "height": 347}, "face_token": "bad2eabbb7ae3c619afd54ee4a081808"}]}
root@01ab7d0c67f7:/home/test# python face++_analyze.py
libudev: udev_has_devtmpfs: name_to_handle_at on /dev: Operation not permitted
图片截取成功
1536937821.32
图片截取成功
1536937821.46
图片截取成功
1536937821.6
{"image_id": "3SYIEreZvIICnN0wcU95Ew==", "faces": [{"face_rectangle": {"width": 291, "top": 87, "left": 339, "height": 291}, "face_token": "79660009ae76fd96dd8fa3d5da8607df"}], "time_used": 549, "thresholds": {"1e-3": 62.327, "1e-5": 73.975, "1e-4": 69.101}, "request_id": "1536937822,56a26d33-05ae-4c90-b71b-5d9aed69951a", "results": [{"confidence": 92.784, "user_id": "", "face_token": "bad2eabbb7ae3c619afd54ee4a081808"}]}

广州美哒-Jack Jiang
{"time_used": 338, "request_id": "1536937823,fdd378b7-d2bb-48fa-874d-bcee65c950cc", "faces": [{"landmark": {"contour_chin": {"y": 501, "x": 175}, "left_eye_upper_left_quarter": {"y": 212, "x": 89}, "mouth_lower_lip_right_contour1": {"y": 391, "x": 203}, "left_eye_bottom": {"y": 233, "x": 106}, "mouth_lower_lip_right_contour2": {"y": 406, "x": 216}, "contour_left7": {"y": 339, "x": 40}, "contour_left6": {"y": 316, "x": 37}, "contour_left5": {"y": 294, "x": 36}, "contour_left4": {"y": 272, "x": 36}, "contour_left3": {"y": 250, "x": 38}, "contour_left2": {"y": 227, "x": 40}, "contour_left1": {"y": 205, "x": 44}, "left_eye_lower_left_quarter": {"y": 230, "x": 89}, "contour_right1": {"y": 210, "x": 380}, "contour_right3": {"y": 262, "x": 382}, "contour_right2": {"y": 236, "x": 381}, "contour_right5": {"y": 313, "x": 380}, "contour_right4": {"y": 287, "x": 381}, "contour_right7": {"y": 364, "x": 374}, "left_eyebrow_left_corner": {"y": 189, "x": 47}, "right_eye_right_corner": {"y": 226, "x": 301}, "nose_bridge1": {"y": 215, "x": 180}, "nose_bridge3": {"y": 266, "x": 171}, "nose_bridge2": {"y": 240, "x": 175}, "right_eyebrow_upper_left_corner": {"y": 182, "x": 209}, "mouth_upper_lip_right_contour4": {"y": 391, "x": 204}, "mouth_upper_lip_right_contour1": {"y": 364, "x": 188}, "right_eye_left_corner": {"y": 229, "x": 232}, "left_eyebrow_upper_right_corner": {"y": 180, "x": 152}, "left_eyebrow_upper_middle": {"y": 165, "x": 97}, "mouth_lower_lip_right_contour3": {"y": 412, "x": 196}, "nose_left_contour3": {"y": 317, "x": 127}, "mouth_lower_lip_bottom": {"y": 413, "x": 173}, "mouth_upper_lip_right_contour2": {"y": 378, "x": 214}, "left_eye_top": {"y": 208, "x": 108}, "nose_left_contour1": {"y": 231, "x": 155}, "mouth_upper_lip_bottom": {"y": 388, "x": 172}, "mouth_upper_lip_left_contour2": {"y": 378, "x": 134}, "mouth_upper_lip_top": {"y": 368, "x": 172}, "mouth_upper_lip_left_contour1": {"y": 364, "x": 156}, "mouth_upper_lip_left_contour4": {"y": 390, "x": 144}, "right_eye_top": {"y": 209, "x": 264}, "mouth_upper_lip_right_contour3": {"y": 396, "x": 226}, "right_eye_bottom": {"y": 233, "x": 266}, "right_eyebrow_lower_left_corner": {"y": 197, "x": 211}, "mouth_left_corner": {"y": 397, "x": 116}, "nose_middle_contour": {"y": 332, "x": 171}, "right_eye_lower_right_quarter": {"y": 231, "x": 284}, "right_eyebrow_lower_right_quarter": {"y": 191, "x": 299}, "contour_right9": {"y": 414, "x": 359}, "mouth_right_corner": {"y": 398, "x": 235}, "right_eye_lower_left_quarter": {"y": 232, "x": 248}, "right_eye_center": {"y": 220, "x": 266}, "left_eye_upper_right_quarter": {"y": 214, "x": 126}, "right_eyebrow_lower_left_quarter": {"y": 190, "x": 240}, "left_eye_pupil": {"y": 219, "x": 109}, "contour_right8": {"y": 389, "x": 368}, "contour_left13": {"y": 464, "x": 87}, "left_eyebrow_lower_right_quarter": {"y": 186, "x": 123}, "left_eye_right_corner": {"y": 229, "x": 139}, "left_eyebrow_lower_right_corner": {"y": 193, "x": 150}, "mouth_upper_lip_left_contour3": {"y": 396, "x": 125}, "left_eyebrow_lower_left_quarter": {"y": 185, "x": 71}, "mouth_lower_lip_left_contour1": {"y": 390, "x": 145}, "mouth_lower_lip_left_contour3": {"y": 411, "x": 151}, "mouth_lower_lip_left_contour2": {"y": 405, "x": 133}, "contour_left9": {"y": 385, "x": 46}, "left_eye_lower_right_quarter": {"y": 231, "x": 123}, "contour_right6": {"y": 338, "x": 378}, "nose_tip": {"y": 291, "x": 167}, "right_eyebrow_upper_middle": {"y": 168, "x": 270}, "right_eyebrow_lower_middle": {"y": 188, "x": 270}, "left_eye_center": {"y": 219, "x": 109}, "right_eyebrow_upper_left_quarter": {"y": 172, "x": 237}, "right_eyebrow_right_corner": {"y": 196, "x": 327}, "right_eyebrow_upper_right_quarter": {"y": 174, "x": 302}, "contour_left16": {"y": 497, "x": 149}, "contour_left15": {"y": 489, "x": 126}, "contour_left14": {"y": 478, "x": 105}, "left_eyebrow_upper_right_quarter": {"y": 170, "x": 126}, "contour_left12": {"y": 448, "x": 72}, "contour_left11": {"y": 429, "x": 60}, "contour_left10": {"y": 408, "x": 52}, "left_eyebrow_lower_middle": {"y": 184, "x": 97}, "left_eyebrow_upper_left_quarter": {"y": 169, "x": 69}, "right_eye_upper_right_quarter": {"y": 214, "x": 284}, "nose_right_contour4": {"y": 327, "x": 207}, "nose_right_contour5": {"y": 329, "x": 189}, "nose_left_contour4": {"y": 324, "x": 141}, "nose_left_contour5": {"y": 327, "x": 155}, "nose_left_contour2": {"y": 288, "x": 139}, "nose_right_contour1": {"y": 232, "x": 207}, "nose_right_contour2": {"y": 290, "x": 214}, "nose_right_contour3": {"y": 321, "x": 224}, "left_eye_left_corner": {"y": 223, "x": 75}, "contour_right15": {"y": 498, "x": 233}, "contour_right14": {"y": 493, "x": 260}, "contour_right16": {"y": 501, "x": 204}, "contour_right11": {"y": 456, "x": 330}, "contour_right10": {"y": 436, "x": 347}, "contour_right13": {"y": 484, "x": 286}, "contour_right12": {"y": 472, "x": 310}, "contour_left8": {"y": 362, "x": 42}, "mouth_lower_lip_top": {"y": 389, "x": 173}, "right_eye_upper_left_quarter": {"y": 215, "x": 246}, "right_eye_pupil": {"y": 220, "x": 266}}, "attributes": {"emotion": {"sadness": 0.007, "neutral": 99.986, "disgust": 0.0, "anger": 0.0, "surprise": 0.004, "fear": 0.0, "happiness": 0.001}, "beauty": {"female_score": 57.238, "male_score": 56.396}, "gender": {"value": "Male"}, "age": {"value": 32}, "mouthstatus": {"close": 100.0, "surgical_mask_or_respirator": 0.0, "open": 0.0, "other_occlusion": 0.0}, "glass": {"value": "None"}, "skinstatus": {"dark_circle": 3.071, "stain": 95.947, "acne": 98.685, "health": 0.981}, "headpose": {"yaw_angle": 8.504396, "pitch_angle": -2.4095645, "roll_angle": -1.6887825}, "blur": {"blurness": {"threshold": 50.0, "value": 0.096}, "motionblur": {"threshold": 50.0, "value": 0.096}, "gaussianblur": {"threshold": 50.0, "value": 0.096}}, "smile": {"threshold": 50.0, "value": 0.003}, "eyestatus": {"left_eye_status": {"normal_glass_eye_open": 0.137, "no_glass_eye_close": 0.0, "occlusion": 0.001, "no_glass_eye_open": 99.862, "normal_glass_eye_close": 0.0, "dark_glasses": 0.0}, "right_eye_status": {"normal_glass_eye_open": 0.005, "no_glass_eye_close": 0.0, "occlusion": 0.0, "no_glass_eye_open": 99.995, "normal_glass_eye_close": 0.0, "dark_glasses": 0.0}}, "facequality": {"threshold": 70.1, "value": 85.438}, "ethnicity": {"value": "ASIAN"}, "eyegaze": {"right_eye_gaze": {"position_x_coordinate": 0.505, "vector_z_component": 0.986, "vector_x_component": 0.165, "vector_y_component": 0.013, "position_y_coordinate": 0.473}, "left_eye_gaze": {"position_x_coordinate": 0.544, "vector_z_component": 0.974, "vector_x_component": 0.225, "vector_y_component": 0.014, "position_y_coordinate": 0.415}}}, "face_rectangle": {"width": 347, "top": 162, "left": 33, "height": 347}, "face_token": "bad2eabbb7ae3c619afd54ee4a081808"}]}

信息量太大,删减一下返回参数;

root@01ab7d0c67f7:/home/test# cp face++_analyze.py face++_analyze_less.py 
root@01ab7d0c67f7:/home/test# nano face++_analyze_less.py 
root@01ab7d0c67f7:/home/test# python face++_analyze_less.py 
libudev: udev_has_devtmpfs: name_to_handle_at on /dev: Operation not permitted
图片截取成功
1536938133.88
图片截取成功
1536938134.02
图片截取成功
1536938134.18
{"image_id": "80Z7Yeo86i2l6Fbic3rJsA==", "faces": [{"face_rectangle": {"width": 344, "top": -14, "left": 298, "height": 344}, "face_token": "827e773e3e1fb5736833e76d2edaf788"}], "time_used": 568, "thresholds": {"1e-3": 62.327, "1e-5": 73.975, "1e-4": 69.101}, "request_id": "1536938134,38d79226-95f6-48b2-8298-c8d0bcaa0dba", "results": [{"confidence": 90.551, "user_id": "", "face_token": "bad2eabbb7ae3c619afd54ee4a081808"}]}

广州美哒-Jack Jiang
{"time_used": 428, "request_id": "1536938135,2f2a0a99-c89e-4325-9d93-ff1702cf3b7d", "faces": [{"attributes": {"emotion": {"sadness": 0.008, "neutral": 99.985, "disgust": 0.0, "anger": 0.0, "surprise": 0.004, "fear": 0.0, "happiness": 0.001}, "skinstatus": {"dark_circle": 3.219, "stain": 96.419, "acne": 98.9, "health": 0.937}, "beauty": {"female_score": 57.219, "male_score": 56.407}, "smile": {"threshold": 50.0, "value": 0.003}, "age": {"value": 32}, "facequality": {"threshold": 70.1, "value": 85.433}}, "face_rectangle": {"width": 347, "top": 162, "left": 33, "height": 347}, "face_token": "bad2eabbb7ae3c619afd54ee4a081808"}]}

代码优化修改:

#coding=utf8
import cv2
import cv2.cv as cv
import requests
import json
import time

i=0
 
capture = cv.CaptureFromCAM(0)              
  
while True:  
    img = cv.QueryFrame(capture)
    cv.ShowImage("camera",img)      
    key = cv.WaitKey(10) 
    time.sleep(5) 
    if i==3:  
        break  
    if i < 3:   
        filename = "face.jpg"  
        cv.SaveImage(filename,img)
        print "图片截取成功"
#读取原图,并显示
        img1 = cv2.imread(filename)
        cv2.namedWindow("原图")
        cv2.imshow("原图", img1)
         
        i+=1
        print(time.time())
        time.sleep(5)

        
del(capture) 
cv.DestroyWindow("camera")

img = cv2.imread('face.jpg') 
url = 'https://api-cn.faceplusplus.com/facepp/v3/search'
payload = {'api_key': "19dI6tJnwhSoAFodyZA2yIucv1npQcO_",
           'api_secret': "DatyybLlcmJyjUZhykGXszZh0tIpQ45x",
           'faceset_token':'f1d4de7b23524374631cff08af33eea5',
           }
files = {'image_file':open('face.jpg', 'rb')}
r = requests.post(url,files=files,data=payload)
data=json.loads(r.text)
print r.text
if data["results"][0]["face_token"] == "bad2eabbb7ae3c619afd54ee4a081808" and data["results"][0]["confidence"]>=data["thresholds"]["1e-5"]:
    print'\n广州美哒-Jack Jiang'
elif data["results"][0]["face_token"] == "c116a106c02f6ffd8606408fe2fb5def"and data["results"][0]["confidence"]>=data["thresholds"]["1e-5"]:
    print'\n广州美哒-Lena'
else:
    print '\n不是我们公司的人员'

url = 'https://api-cn.faceplusplus.com/facepp/v3/face/analyze'
payload = {'api_key': "19dI6tJnwhSoAFodyZA2yIucv1npQcO_",
           'api_secret': "DatyybLlcmJyjUZhykGXszZh0tIpQ45x",
           'face_tokens':data["faces"][0]["face_token"],
           'return_landmark': 0,
           'return_attributes':'age,skinstatus',
}

files = {'image_file':open('face.jpg', 'rb')}
r = requests.post(url,files=files,data=payload)
data=json.loads(r.text)
print r.text

qrcont=r.text
 
#进过测试前面的程序会返回一个字典,其中指出了人脸所在的矩形的位置和大小等,所以直接进行标注
mydict = eval(qrcont)
faces = mydict["faces"]

print(faces)
faceNum = len(faces)
print("识别到了%d个人脸"%(faceNum))



for i in range(faceNum):
    face_rectangle = faces[i]['face_rectangle']
    width =  face_rectangle['width']
    top =  face_rectangle['top']
    left =  face_rectangle['left']
    height =  face_rectangle['height']
    start = (left, top)
    end = (left+width, top+height)
    color = (55,255,155)
    thickness = 3
    cv2.rectangle(img, start, end, color, thickness)



cv2.namedWindow("识别后")
cv2.imshow("识别后", img)
print('end')

cv2.waitKey(0)
cv2.destroyAllWindows()

测试结果:

root@01ab7d0c67f7:/home/test# python face++_analyze_showimg.py
libudev: udev_has_devtmpfs: name_to_handle_at on /dev: Operation not permitted
图片截取成功
1536941349.23
图片截取成功
1536941349.39
图片截取成功
1536941349.65
{"image_id": "DfA9/6iOTCIzCWWVQ6K8Iw==", "faces": [{"face_rectangle": {"width": 404, "top": 40, "left": 196, "height": 404}, "face_token": "ab3f6d9d93566df201ef7628ad3c0f72"}], "time_used": 547, "thresholds": {"1e-3": 62.327, "1e-5": 73.975, "1e-4": 69.101}, "request_id": "1536941351,64f42ea9-f9ce-4300-82a5-2e2a21db9481", "results": [{"confidence": 91.014, "user_id": "", "face_token": "bad2eabbb7ae3c619afd54ee4a081808"}]}

广州美哒-Jack Jiang
{"time_used": 468, "request_id": "1536941352,1186706d-2d59-46bd-aa29-de30b1062222", "faces": [{"attributes": {"age": {"value": 32}, "skinstatus": {"dark_circle": 3.219, "stain": 96.419, "acne": 98.9, "health": 0.937}}, "face_rectangle": {"width": 347, "top": 162, "left": 33, "height": 347}, "face_token": "bad2eabbb7ae3c619afd54ee4a081808"}]}
识别到了1个人脸
end
root@01ab7d0c67f7:/home/test# nano face++_analyze_showimg.py
root@01ab7d0c67f7:/home/test# python face++_analyze_showimg.py
libudev: udev_has_devtmpfs: name_to_handle_at on /dev: Operation not permitted
图片截取成功
^CTraceback (most recent call last):
  File "face++_analyze_showimg.py", line 27, in <module>
    time.sleep(100) 
KeyboardInterrupt
root@01ab7d0c67f7:/home/test# nano face++_analyze_showimg.py
root@01ab7d0c67f7:/home/test# python face++_analyze_showimg.py
libudev: udev_has_devtmpfs: name_to_handle_at on /dev: Operation not permitted
图片截取成功
1536941968.62
图片截取成功
1536941988.82
图片截取成功
1536942008.98
{"image_id": "Yzsc9zAJTdvuoR8ENJ6Clg==", "faces": [{"face_rectangle": {"width": 386, "top": 23, "left": 221, "height": 386}, "face_token": "c3cf3c9af745babf08fc06d1a1083bde"}], "time_used": 557, "thresholds": {"1e-3": 62.327, "1e-5": 73.975, "1e-4": 69.101}, "request_id": "1536942019,05cff9dc-193f-42ac-8d53-acfc7119a6c2", "results": [{"confidence": 88.724, "user_id": "", "face_token": "bad2eabbb7ae3c619afd54ee4a081808"}]}

广州美哒-Jack Jiang
{"time_used": 451, "request_id": "1536942020,59b76b66-652b-45fe-9e2d-ce9365a2809b", "faces": [{"attributes": {"age": {"value": 32}, "skinstatus": {"dark_circle": 3.219, "stain": 96.419, "acne": 98.9, "health": 0.937}}, "face_rectangle": {"width": 347, "top": 162, "left": 33, "height": 347}, "face_token": "bad2eabbb7ae3c619afd54ee4a081808"}]}
识别到了1个人脸
end
root@01ab7d0c67f7:/home/test# nano face++_analyze_showimg1.py
root@01ab7d0c67f7:/home/test# python face++_analyze_showimg1.py
libudev: udev_has_devtmpfs: name_to_handle_at on /dev: Operation not permitted
图片截取成功
1536942678.64
图片截取成功
1536942698.87
图片截取成功
1536942718.96
{"image_id": "oz16O4IOk+XxKzUNZXVqvA==", "faces": [{"face_rectangle": {"width": 368, "top": 85, "left": 264, "height": 368}, "face_token": "2b402425b528337bd2ec050038d1ccb9"}], "time_used": 553, "thresholds": {"1e-3": 62.327, "1e-5": 73.975, "1e-4": 69.101}, "request_id": "1536942739,9e04ca7a-70e1-4fbe-a9f4-f07c030bacdd", "results": [{"confidence": 93.308, "user_id": "", "face_token": "bad2eabbb7ae3c619afd54ee4a081808"}]}

广州美哒-Jack Jiang
{"time_used": 424, "request_id": "1536942740,a07b40ad-0ccb-4c41-a95f-f97fdee06f05", "faces": [{"attributes": {"age": {"value": 32}, "skinstatus": {"dark_circle": 3.071, "stain": 95.947, "acne": 98.685, "health": 0.981}}, "face_rectangle": {"width": 347, "top": 162, "left": 33, "height": 347}, "face_token": "bad2eabbb7ae3c619afd54ee4a081808"}]}
识别到了1个人脸
end

标注方框不准,是由于用的基准的图片方框数据,标注到测试图片上;

最终代码:

#coding=utf8
import cv2
import cv2.cv as cv
import requests
import json
import time

i=0
 
capture = cv.CaptureFromCAM(0)              
  
while True:  
    img = cv.QueryFrame(capture)
    cv.ShowImage("camera",img)      
    key = cv.WaitKey(10) 
    time.sleep(3) 
    if i==3:  
        break  
    if i < 3:   
        filename = "face.jpg"  
        cv.SaveImage(filename,img)
        print "图片截取成功"
#读取原图,并显示
        img1 = cv2.imread(filename)
        cv2.namedWindow("原图")
        cv2.imshow("原图", img1)
         
        i+=1
        print(time.time())
        time.sleep(3)

        
del(capture) 
cv.DestroyWindow("camera")

img = cv2.imread('face.jpg') 
url = 'https://api-cn.faceplusplus.com/facepp/v3/search'
payload = {'api_key': "19dI6tJnwhSoAFodyZA2yIucv1npQcO_",
           'api_secret': "DatyybLlcmJyjUZhykGXszZh0tIpQ45x",
           'faceset_token':'f1d4de7b23524374631cff08af33eea5',
           }
files = {'image_file':open('face.jpg', 'rb')}
r = requests.post(url,files=files,data=payload)
data=json.loads(r.text)
print r.text

qrcont=r.text
 
#进过测试前面的程序会返回一个字典,其中指出了人脸所在的矩形的位置和大小等,所以直接进行标注
mydict = eval(qrcont)
faces = mydict["faces"]
faceNum = len(faces)
print("识别到了%d个人脸"%(faceNum))


for i in range(faceNum):
    face_rectangle = faces[i]['face_rectangle']
    width =  face_rectangle['width']
    top =  face_rectangle['top']
    left =  face_rectangle['left']
    height =  face_rectangle['height']
    start = (left, top)
    end = (left+width, top+height)
    color = (55,255,155)
    thickness = 3
    cv2.rectangle(img, start, end, color, thickness)
    cv2.namedWindow("识别后")
    cv2.imshow("识别后", img)

if data["results"][0]["face_token"] == "bad2eabbb7ae3c619afd54ee4a081808" and data["results"][0]["confidence"]>=data["thresholds"]["1e-5"]:
    print'\n广州美哒-Jack Jiang'
elif data["results"][0]["face_token"] == "c116a106c02f6ffd8606408fe2fb5def"and data["results"][0]["confidence"]>=data["thresholds"]["1e-5"]:
    print'\n广州美哒-Lena'
else:
    print '\n不是我们公司的人员'


print(data["faces"][0]["face_token"])

url = 'https://api-cn.faceplusplus.com/facepp/v3/face/analyze'
payload = {'api_key': "19dI6tJnwhSoAFodyZA2yIucv1npQcO_",
           'api_secret': "DatyybLlcmJyjUZhykGXszZh0tIpQ45x",
           'face_tokens':data["faces"][0]["face_token"],
           'return_landmark': 0,
           'return_attributes':'age,beauty,skinstatus',
}

files = {'image_file':open('face.jpg', 'rb')}
r = requests.post(url,files=files,data=payload)
data=json.loads(r.text)
print data






print('end')

cv2.waitKey(0)
cv2.destroyAllWindows()

测试结果:

root@01ab7d0c67f7:/home/test# nano face++_analyze_showimg3.py
root@01ab7d0c67f7:/home/test# python face++_analyze_showimg2.py
libudev: udev_has_devtmpfs: name_to_handle_at on /dev: Operation not permitted
图片截取成功
1536974529.88
图片截取成功
1536974540.01
图片截取成功
1536974550.12
{"image_id": "Ujd/lXJrbM7rXnVTmpMpNw==", "faces": [{"face_rectangle": {"width": 390, "top": 194, "left": 259, "height": 390}, "face_token": "7289001f6f874ce155e75cd38df4a898"}], "time_used": 573, "thresholds": {"1e-3": 62.327, "1e-5": 73.975, "1e-4": 69.101}, "request_id": "1536974561,766ad9b4-b370-4527-a363-33fef05ef496", "results": [{"confidence": 87.072, "user_id": "", "face_token": "bad2eabbb7ae3c619afd54ee4a081808"}]}

广州美哒-Jack Jiang
{"time_used": 533, "request_id": "1536974562,d024cb97-0126-480d-a5b0-11841935948a", "faces": [{"attributes": {"age": {"value": 32}, "skinstatus": {"dark_circle": 3.219, "stain": 96.419, "acne": 98.9, "health": 0.937}}, "face_rectangle": {"width": 347, "top": 162, "left": 33, "height": 347}, "face_token": "bad2eabbb7ae3c619afd54ee4a081808"}]}
识别到了1个人脸
end
root@01ab7d0c67f7:/home/test# nano face++_analyze_showimg3.py
root@01ab7d0c67f7:/home/test# python face++_analyze_showimg3.py
libudev: udev_has_devtmpfs: name_to_handle_at on /dev: Operation not permitted
图片截取成功
1536976546.92
图片截取成功
1536976553.1
图片截取成功
1536976559.28
{"image_id": "hj2VXNBBofl4KUZ/9nAMGg==", "faces": [{"face_rectangle": {"width": 447, "top": 104, "left": 189, "height": 447}, "face_token": "858e351805411b4d28374610addbf32f"}], "time_used": 524, "thresholds": {"1e-3": 62.327, "1e-5": 73.975, "1e-4": 69.101}, "request_id": "1536976566,8b727b49-e0bf-4cce-97d3-72382c1a9258", "results": [{"confidence": 89.141, "user_id": "", "face_token": "bad2eabbb7ae3c619afd54ee4a081808"}]}
识别到了1个人脸

广州美哒-Jack Jiang
bad2eabbb7ae3c619afd54ee4a081808
{"time_used": 502, "request_id": "1536976567,10a07992-8b79-4242-be49-8b667294dbc0", "faces": [{"attributes": {"age": {"value": 32}, "skinstatus": {"dark_circle": 3.219, "stain": 96.419, "acne": 98.9, "health": 0.937}, "beauty": {"female_score": 57.219, "male_score": 56.407}}, "face_rectangle": {"width": 347, "top": 162, "left": 33, "height": 347}, "face_token": "bad2eabbb7ae3c619afd54ee4a081808"}]}
end

注意:faces_token的读取

data["faces"][0]["face_token"],

 json.loads()用于将str类型的数据转成dict。取出faces里面的faces_token,注意不是result里面的faces_token;

root@01ab7d0c67f7:/home/test# nano face++_analyze_showimg3.py
root@01ab7d0c67f7:/home/test# python face++_analyze_showimg3.py
libudev: udev_has_devtmpfs: name_to_handle_at on /dev: Operation not permitted
图片截取成功
1536979736.71
图片截取成功
1536979742.84
图片截取成功
1536979749.04
{"image_id": "OZCKSiSjlvC3f4LtkXpVFw==", "faces": [{"face_rectangle": {"width": 305, "top": 27, "left": 301, "height": 305}, "face_token": "cf6ab6f3ab2ac25f499f04a8db21b4e5"}], "time_used": 517, "thresholds": {"1e-3": 62.327, "1e-5": 73.975, "1e-4": 69.101}, "request_id": "1536979755,76a36250-c4f2-4e08-901e-5858a97adf36", "results": [{"confidence": 89.462, "user_id": "", "face_token": "bad2eabbb7ae3c619afd54ee4a081808"}]}
识别到了1个人脸

广州美哒-Jack Jiang
cf6ab6f3ab2ac25f499f04a8db21b4e5
{u'time_used': 159, u'faces': [{u'attributes': {u'age': {u'value': 32}, u'skinstatus': {u'health': 1.785, u'stain': 16.077, u'acne': 15.358, u'dark_circle': 2.779}, u'beauty': {u'female_score': 66.878, u'male_score': 68.165}}, u'face_token': u'cf6ab6f3ab2ac25f499f04a8db21b4e5', u'face_rectangle': {u'width': 305, u'top': 27, u'height': 305, u'left': 301}}], u'request_id': u'1536979756,6feb2251-fd1c-4fb4-a008-0b1acd933e50'}
end

参考链接:

Face Analyze API

https://console.faceplusplus.com.cn/documents/4888383

猜你喜欢

转载自blog.csdn.net/jacka654321/article/details/82709346