面部特征分析
旷视 官方文档
根据单张正面人脸图片,分析人脸面部特征
基本说明:
接口地址:https://api-cn.faceplusplus.com/facepp/v1/facialfeatures
返回格式:json
请求方式:post
请求示例:https://api-cn.faceplusplus.com/facepp/v1/facialfeatures?api_key=k&api_secret=s&image_url=u1
请求参数说明:
名称 类型 必填 说明
api_key string 必填 调用此API的API Key 扫码关注公众号
api_secret string 必填 调用此API的API Secret 扫码关注公众号
image_url string 必填 图片的 URL
return_imagereset string 必填 是否返回人脸矫正后图片。1返回0不返回
返回参数说明:
名称 类型 说明
- - 详情见json
JSON返回示例:
{
	"image_reset": "NTyDKpmLM7RklVcRyv2xPA==",
	"request_id": "1528687092,efbe87f7-6c0f-4754-b108-afe8f42abe17",
	"time_used": 666,
	"face_rectangle": {

		"top": 1,
		"left": 1,
		"wilewdth": 1,
		"height": 1
	},
	"result": {
		"three_parts": {
			"parts_ratio": "0.33:0.34:0.33",
			"one_part": {
				"faceup_length": 73.33,
				"faceup_ratio": 0.33,
				"faceup_result": "faceup_normal"
			},
			"two_part": {
				"facemid_length": 74.12,
				"facemid_ratio": 0.34,
				"facemid_result": "facemid_normal"
			},
			"three_part": {
				"facedown_length": 72.42,
				"facedown_ratio": 0.33,
				"facedown_result": "facedown_long"
			}
		},
		"five_eyes": {
			"eyes_ratio": "0.80:1:1.41:1:0.80",
			"one_eye": {
				"righteye_empty_length": 24.21,
				"righteye_empty_ratio": 0.80,
				"righteye_empty_result": "righteye_empty_normal"
			},
			"righteye": 25.42,
			"three_eye": {
				"eyein_length": 24.31,
				"eyein_ratio": 1.41,
				"eyein_result": "eyein_long"
			},
			"lefteye": 25.46,
			"five_eye": {
				"lefteye_empty_length": 24.23,
				"lefteye_empty_ratio": 0.80,
				"lefteye_empty_result": "lefteye_empty_short"
			}
		},
		"golden_triangle": 62.14,
		"face": {
			"tempus_length": 112.15,
			"zygoma_length": 135.36,
			"face_length": 219.41,
			"mandible_length": 104.11,
			"E": 116.00,
			"ABD_ratio": "1.31:1:1.45",
			"face_type": "pointed_face"
		},
		"jaw": {
			"jaw_width": 29.61,
			"jaw_length": 15.03,
			"jaw_type": "sharp_jaw"
		},
		"eyebrow": {
			"brow_width": 33.12,
			"brow_height": 5.17,
			"brow_uptrend_angle": 21.04,
			"brow_camber_angle": 8.76,
			"brow_thick": 3.17,
			"eyebrow_type": "bushy_eyebrows"
		},
		"eyes": {
			"eye_width": 20.35,
			"eye_height": 8.66,
			"angulus_oculi_medialis": 58.32,
			"eyes_type": "big_eyes"
		},
		"nose": {
			"nose_width": 28.12,
			"nose_type": "thick_nose"
		},
		"mouth": {
			"mouth_height": 11.37,
			"mouth_width": 42.34,
			"lip_thickness": 6.8,
			"angulus_oris": 85.67,
			"mouth_type": "thin_lip"
		}
	}
}
服务级错误码参照
错误码 说明
400 IMAGE_ERROR_UNSUPPORTED_FORMAT:参数<param>对应的图像无法正确解析,有可能不是一个图像文件、或有数据破损、或图片文件格式不符合要求。
400 INVALID_IMAGE_SIZE:客户上传的图像像素尺寸太大或太小,图片要求请参照本API描述。<param>对应图像太大的那个参数的名称
400 INVALID_IMAGE_URL:无法从指定的image_url下载图片,图片URL错误或者无效
400 IMAGE_FILE_TOO_LARGE:客户通过参数<param>上传的图片文件太大。本 API 要求图片文件大小不超过 2 MB
403 INSUFFICIENT_PERMISSION:试用 API Key 无法使用 <param>对应的参数。请勿传入此参数。或者使用正式 API Key 调用。
412 IMAGE_DOWNLOAD_TIMEOUT:下载图片超时
完整教学代码示例
<?php
/**
 * Created by PhpStorm.
 * User: FZS
 * Time: 2020/10/10 17:50
 */
//----------------------------------
// 面部特征分析 调用类
//----------------------------------
class freeApi
{
    private $apiKey = false;
    private $apiSecret = false;
    private $apiUrl = 'https://api-cn.faceplusplus.com/facepp/v1/facialfeatures';
    public function __construct($apikey,$apiSecret){
        $this->apiKey = $apikey;
        $this->apiSecret = $apiSecret;
    }
    /**
     * 将JSON内容转为数据,并返回
     * @param string $content [内容]
     * @return array
     */
    public function returnArray($content){
        return json_decode($content,true);
    }
    /**
     * 获取结果
     * @return array
     */
    public function getResult(){
        $params = [
            "api_key" => $this->apiKey,
            "api_secret" => $this->apiSecret,
            "image_url" => "",
        ];
        $params = http_build_query($params);
        return $this->returnArray($this->freeApiCurl($this->apiUrl,$params,1));
    }
    /**
     * 请求接口返回内容
     * @param  string $url [请求的URL地址]
     * @param  string $params [请求的参数]
     * @param  int $ipost [是否采用POST形式]
     * @return  string
     */
    public function freeApiCurl($url,$params=false,$ispost=0){
        $ch = curl_init();
        curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
        curl_setopt( $ch , CURLOPT_SSL_VERIFYHOST , false );
        curl_setopt( $ch , CURLOPT_SSL_VERIFYPEER , false );
        curl_setopt( $ch, CURLOPT_USERAGENT , 'free-api' );
        curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
        curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
        curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
        if( $ispost )
        {
            curl_setopt( $ch , CURLOPT_POST , true );
            curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
            curl_setopt( $ch , CURLOPT_URL , $url );
        }
        else
        {
            if($params){
                curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
            }else{
                curl_setopt( $ch , CURLOPT_URL , $url);
            }
        }
        $response = curl_exec( $ch );
        if ($response === FALSE) {
            return false;
        }
        curl_close( $ch );
        return $response;
    }
}