接口地址:https://api-cn.faceplusplus.com/facepp/v3/detect |
---|
返回格式:json |
请求方式:post |
请求示例:https://api-cn.faceplusplus.com/facepp/v3/detect?api_key=yourkey&api_secret=yoursecret&image_url=url |
名称 | 类型 | 必填 | 说明 |
---|---|---|---|
api_key | string | 必填 | 调用此API的API Key 扫码关注公众号 |
api_secret | string | 必填 | 调用此API的API Secret 扫码关注公众号 |
image_url | string | 必填 | 图片的 URL |
名称 | 类型 | 说明 |
---|---|---|
request_id | string | 用于区分每一次请求的唯一的字符串。 |
faces | array | 被检测出的人脸数组,具体包含内容见下文。注:如果没有检测出人脸则为空数组 |
image_id | string | 被检测的图片在系统中的标识。 |
time_used | int | 整个请求所花费的时间,单位为毫秒。 |
error_message | string | 当请求失败时才会返回此字符串,具体返回内容见后续错误信息章节。否则此字段不存在。 |
face_num | int | 检测出的人脸个数 |
{
"image_id": "Dd2xUw9S/7yjr0oDHHSL/Q==",
"request_id": "1470472868,dacf2ff1-ea45-4842-9c07-6e8418cea78b",
"time_used": 752,
"faces": [{
"landmark": {
"mouth_upper_lip_left_contour2": {
"y": 185,
"x": 146
},
"contour_chin": {
"y": 231,
"x": 137
},
"right_eye_pupil": {
"y": 146,
"x": 205
},
"mouth_upper_lip_bottom": {
"y": 195,
"x": 159
}
},
"attributes": {
"gender": {
"value": "Female"
},
"age": {
"value": 21
},
"glass": {
"value": "None"
},
"headpose": {
"yaw_angle": -26.625063,
"pitch_angle": 12.921974,
"roll_angle": 22.814377
},
"smile": {
"threshold": 30.1,
"value": 2.566890001296997
}
},
"face_rectangle": {
"width": 140,
"top": 89,
"left": 104,
"height": 141
},
"face_token": "ed319e807e039ae669a4d1af0922a0c8"
}],
"face_num": 1
}
错误码 | 说明 |
---|---|
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/v3/detect';
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_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
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;
}
}