接口地址:https://api-cn.faceplusplus.com/facepp/v1/face/thousandlandmark |
---|
返回格式:json |
请求方式:post |
请求示例:https://api-cn.faceplusplus.com/facepp/v1/face/thousandlandmark?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_landmark | string | 必填 | 是否检测并返回人脸关键点,所有为all,指定的为该器官英文单词 |
名称 | 类型 | 说明 |
---|---|---|
- | - | 详情见json |
{
"time_used": 339,
"request_id": "1548051575,97f2634e-cf29-4afa-8bc0-ff48f501828b",
"face": {
"landmark": {
"left_eyebrow": {
"left_eyebrow_54": {
"y": 171,
"x": 217
},
"left_eyebrow_55": {
"y": 171,
"x": 215
},
"left_eyebrow_52": {
"y": 171,
"x": 221
},
"left_eyebrow_53": {
"y": 171,
"x": 219
},
"left_eyebrow_50": {
"y": 170,
"x": 225
},
"left_eyebrow_51": {
"y": 170,
"x": 223
},
"left_eyebrow_56": {
"y": 172,
"x": 213
},
"left_eyebrow_57": {
"y": 172,
"x": 211
},
"left_eyebrow_18": {
"y": 159,
"x": 229
},
"left_eyebrow_19": {
"y": 159,
"x": 232
},
"left_eyebrow_16": {
"y": 159,
"x": 225
},
"left_eyebrow_17": {
"y": 159,
"x": 227
},
"right_eyebrow_7": {
"y": 178,
"x": 358
},
"right_eyebrow_62": {
"y": 186,
"x": 360
},
"right_eyebrow_63": {
"y": 187,
"x": 362
}
}
},
"face_rectangle": {
"width": 216,
"top": 164,
"height": 217,
"left": 161
}
}
}
错误码 | 说明 |
---|---|
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/v2/beautify';
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;
}
}