文档简介:
电子围栏接口说明
接口描述
用于自动检测指定图片中的指定区域内是否有行人存在,返回指定区域内存在的行人位置
接口要求
格式说明:
1. 图片格式支持 png、jpg、jpeg等格式
2. 批量请求单次中,通过base64的形式上传图片,不大于50M
请求说明
-
请求示例
HTTP方法:POST
电子围栏检测URL:https://ai.ctyun.cn/v1/aiop/api/[系统生成的服务码]/ef-http/electron/fence
-
请求头说明
参数 |
值(说明) |
Content-Type |
application/json |
Sign |
MD5(AppKey + AppSecret + Timestamp + Path + Http Body),32位小写的MD5加密串 |
Timestamp |
13位时间戳 |
AppKey |
平台分配给应用独立的AppKey |
-
请求参数
参数 |
是否必选 |
类型 |
可选值范围 |
说明 |
area |
true |
string |
- |
设置电子围栏区域'x1,y1,x2,y2,x3,y3,x4,y4',数据类型为字符串,坐标点数量大于3小于10,逆时针或顺时针排序。 |
image |
true |
list |
- |
请求参数放置于http body中,一张或多张图像Base64编码数据构成的list。注意:图片需要使用常规base64编码方式 |
-
请求示例代码
Bash:
curl -X POST https://ai.ctyun.cn/v1/aiop/api/[系统生成的服务码]/ef-http/electron/fence -H "Content-Type: application/json" -H 'Sign: XXXXX' -H 'Timestamp: XXXXX' -H 'AppKey: XXXXX' --data '{"image": ["AAAAAAAAAA...."], "area": "0,0,1920,0,1920,1080,0,1080"}'
Python:
# -*- coding: utf-8 -*-
import requests
import base64
import hashlib
import time
import json
'''
电子围栏检测
'''
def md5(key):
input_name = hashlib.md5()
input_name.update(key.encode("utf-8"))
return input_name.hexdigest()
request_url = "围栏检测的API URL"
area_string = "围栏区域坐标点"
# 二进制方式打开图片文件
f = open('[本地文件]', 'rb')
img = base64.b64encode(f.read()).decode()
infer_params = {"image": [img], "area": area_string}
app_key = '平台分配的APP Key'
app_secret = '平台分配的APP Secret '
time_stamp = str(int(round(time.time() * 1000)))
headers = {
'content-type': 'application/json',
'Sign': md5(app_key + app_secret + time_stamp + '/v1/aiop/api/[系统生成的服务码]/electron/fence' + json.dumps(infer_params)),
'Timestamp': time_stamp,
'AppKey': app_key
}
response = requests.post(request_url, data=json.dumps(infer_params), headers=headers)
if response:
print(response.json())
返回说明
-
API调用成功返回值
返回字段 |
是否必选 |
类型 |
字段说明 |
code |
true |
int |
返回状态,返回0表示成功,其他表示返回错误 |
message |
true |
object |
请求信息结构体,message["success"]代表请求list中的成功数量,message["fail"]代表请求list中的失败数量。 |
result |
false |
list |
返回检测结果列表 |
target_num |
true |
int |
返回违规区域内目标数量 |
location |
true |
list |
返回违规区域内目标位置信息,list中元素为dict |
location[][‘left’] |
true |
int |
返回目标左上角位置坐标x |
location[][‘top] |
true |
int |
返回目标左上角位置坐标y |
location[][‘width] |
true |
int |
返回目标宽度 |
location[][‘height’] |
true |
int |
返回目标高度 |
-
API调用失败返回值
返回字段 |
是否必选 |
类型 |
字段说明 |
code |
true |
int |
错误码,参见本文档错误码说明部分 |
message |
true |
string |
返回对应的可读消息,值为error |
details |
true |
string |
错误消息 |
-
返回示例
HTTP/1.1 200 OK
Content-Type: application/json
{
"code":0,
"message":{"success":1,"fail":0}
"result":[{
"target_num":2,
"location":[
{
"left":209,
"top":229,
"width":341,
"height":1202
},
{
"left":971,
"top":409,
"width":387,
"height":1149
}
]
}]
}
错误码说明
错误代码 |
错误消息 |
错误可能原因 |
4000 |
请求路径错误 |
请求路径的相关错误 |
4001 |
请求方法错误,仅支持POST |
请求使用了GET |
4002 |
请求体数据量超限,最大支持50M |
请求体数据量过大 |
4003 |
请求体解析错误,仅支持json |
请求的body解析失败 |
4004 |
请求体格式错误,json内容不能为空 |
请求的body不是字典类型 |
4005 |
请求参数中缺少关键字,仅支持image和area |
请求body中的参数名错误 |
4006 |
请求参数类型错误,image仅支持list |
参数image的格式需要为list |
4007 |
请求参数内容错误,list不能为空或大于32 |
参数image的list内容为空长度超限 |
4008 |
请求参数内容错误,list中图像信息不能为空 |
图像信息为空 |
4009 |
请求参数内容错误,图像解析失败 |
图像解析不成功 |
4011 |
请求参数类型错误,area仅支持string |
传递的area值需要为string |
4012 |
请求参数内容错误,area字符串不符合要求 |
设置电子围栏区域'x1,y1,x2,y2,x3,y3,x4,y4',数据类型为字符串,坐标点数量大于3小于10, 逆时针或顺时针排序 |
4013 |
请求参数错误,area超出图像范围 |
参数area范围超过图像区域 |
5000 |
服务错误 |
未被识别的异常错误 |
5001 |
推理服务异常,请联系管理员 |
推理过程中服务处理失败 |
5002 |
数据库服务异常,请联系管理员 |
数据库处理错误 |