接口地址:https://api-cn.faceplusplus.com/humanbodypp/v1/gesture |
---|
返回格式:json |
请求方式:post |
请求示例:https://api-cn.faceplusplus.com/humanbodypp/v1/gesture?api_key=1&api_secret=2&image_url=3 |
名称 | 类型 | 必填 | 说明 |
---|---|---|---|
api_key | string | 必填 | Face++的 API Key 扫码关注公众号 |
api_secret | string | 必填 | Face++的 API Secret 扫码关注公众号 |
image_url | string | 必填 | 图片的 URL |
return_gesture | string | 选填 | 是否计算并返回每个手的手势信息。合法值为:1或0 |
名称 | 类型 | 说明 |
---|---|---|
request_id | string | 用于区分每一次请求的唯一的字符串。 |
hands | array | 被检测出的手部数组 |
image_id | string | 被检测的图片在系统中的标识 |
time_used | int | 整个请求所花费的时间,单位为毫秒。 |
error_message | string | 当请求失败时才会返回此字符串,具体返回内容见后续错误信息章节。否则此字段不存在。 |
hand_rectangle | object | 手部矩形框,坐标数字为整数,代表像素点坐标。top:左上角纵坐标left:左上角横坐标width:宽度height:高度 |
gesture | object | 手势识别结果,包括以下字段。每个字段的值是一个浮点数,范围 [0,100],小数点后3位有效数字,总和等于100。 unknown:未定义手势 heart_a:比心 A heart_b:比心 B heart_c:比心 C heart_d:比心 D ok:OK hand_open:手张开 thumb_up:大拇指向上 thumb_down:大拇指向下 rock:ROCK namaste:合十 palm_up:手心向上 fist:握拳 index_finger_up:食指朝上 double_finger_up:双指朝上 victory:胜利 big_v:大 V 字 phonecall:打电话 beg:作揖 thanks:感谢 |
{
"image_id": "7OO7N1dYiJjszvV38oKVpw==",
"request_id": "1491569448,de5a441f-6c6f-4955-896c-37b8bb2d4197",
"time_used": 915,
"hands": [{
"gesture": {
"unknown": 0,
"heart_a": 99,
"heart_b": 1,
"heart_c": 0,
"heart_d": 0,
"ok": 0,
"hand_open": 0,
"thumb_up": 0,
"thumb_down": 0,
"rock": 0,
"namaste": 0,
"palm_up": 0,
"fist": 0,
"index_finger_up": 0,
"double_finger_up": 0,
"victory": 0,
"big_v": 0,
"phonecall": 0,
"beg": 0,
"thanks": 0
},
"hand_rectangle": {
"width": 456,
"top": 0,
"height": 500,
"left": 0
}
}]
}
错误码 | 说明 |
---|---|
401 | api_key 和 api_secret 不匹配。 |
403 | api_key 没有调用本 API 的权限,具体原因为:用户自己禁止该 api_key 调用、管理员禁止api_key 调用、由于账户余额不足禁止调用。 |
403 | 并发数超过限制。 |
400 | 缺少某个必选参数。 |
400 | 某个参数解析出错(比如必须是数字,但是输入的是非数字字符串; 或者长度过长,etc.) |
400 | 同时传入了要求是二选一或多选一的参数。如有特殊说明则不返回此错误。 |
413 | 客户发送的请求大小超过了 2MB 限制。该错误的返回格式为纯文本,不是 json 格式。 |
404 | 所调用的 API 不存在。 |
500 | 服务器内部错误,当此类错误发生时请再次请求,如果持续出现此类错误,请及时联系技术支持团队。 |
<?php
/**
* Created by PhpStorm.
* User: FZS
* Time: 2020/11/02 21:53
*/
//----------------------------------
// 手势识别 调用类
//----------------------------------
class freeApi
{
private $apiKey = false;
private $apiSecret = false;
private $apiUrl = 'https://api-cn.faceplusplus.com/humanbodypp/v1/gesture';
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;
}
}