API Path
/aipaas/live/v1/detection/silent
请求协议
HTTPS
请求方法
POST
请求头部 :
| 头部标签 | 必填 | 说明 | 类型 | 数据字典 | 限制 | 头部内容 | 示例 |
|---|---|---|---|---|---|---|---|
| Content-Type | 是 | application/json | [string] | application/json | application/json | ||
| X-APP-ID | 是 | 控制台-应用管理-创建应用-AppID | [string] | ||||
| Device-Uuid | 否 | 设备管理-设备uuid | [string] | ||||
| Authorization | 是 | 鉴权信息 | [string] |
请求参数 Json:
| 参数名 | 说明 | 必填 | 类型 | 数据字典 | 限制 | 示例 |
|---|---|---|---|---|---|---|
| code | 必须为1019, 图片流创建任务代号 | 是 | [int] | |||
| data | 是 | [object] | ||||
| data>>taskId | 任务id | 是 | [string] | |||
| data>>algoTasks | 任务列表 | 是 | [array] | |||
| data>>algoTasks>>algoTask | 必须为1031 | 是 | [int] | |||
| data>>algoTasks>>algoConfig | 否 | [object] | ||||
| data>>algoTasks>>algoConfig>>silentface | 任务类型 | 否 | [object] | |||
| data>>algoTasks>>algoConfig>>silentface>>algoType | 算法组类型,此任务为1031,如果填的格式错误或数值不对,或没有填,不报错(为了兼容线上版本) | 否 | [number] | |||
| data>>imageList | 图片列表支撑多张图,输入的图片的分辨率必须保持一致,否则会报错,建议不超过8张图 | 是 | [array] | |||
| data>>imageList>>image | 图片base64 | 是 | [string] |
响应内容 :
返回结果
> 成功 (200)
> Json
> Object
| 参数名 | 说明 | 必填 | 类型 | 数据字典 | 限制 | 示例 |
|---|---|---|---|---|---|---|
| code | 图片流返回码 | 是 | [number] | |||
| data | 是 | [object] | ||||
| data>>task_id | 任务 id,透传输入参数 | 否 | [string] | |||
| data>>frame_id | 图片帧号, 图片流此字段无意义 | 否 | [number] | |||
| data>>frame_pts | 视频流用的,图片流此字段无意义,忽略 | 否 | [number] | |||
| data>>timestamp | 时间戳 | 否 | [number] | |||
| data>>frame_image | 视频流使用,此能力返回空,无意义 | 否 | [string] | |||
| data>>src_width | 图片原始宽度 | 否 | [int] | |||
| data>>src_height | 图片原始高度 | 否 | [int] | |||
| data>>frame_width | 对于图片流此字段跟 src_width 值相同 | 否 | [int] | |||
| data>>frame_height | 对于图片流此字段跟 src_height 值相 同 | 否 | [int] | |||
| data>>algo_task | 任务编号 | 否 | [string] | |||
| data>>results | 否 | [array] | ||||
| data>>results>>algo_type | 任务类型编号 | 否 | [string] | |||
| data>>results>>score | 绝对静默活体标准映射分(-1为没有检测到活体) | 否 | [float] | |||
| data>>detect_objects | 此任务返回空列表 | 否 | [array] | |||
| data>>task_code | 错误编码, 异常时返回 | 否 | [int] | |||
| data>>msg | 具体的错误信息,异常时返回 | 否 | [string] |
成功示例[Mock API] :
{
"code": 1020,
"data": {
"task_id": "task_1",
"frame_id": 0,
"src_width": 1024,
"src_height": 1024,
"frame_width": 1024,
"frame_height": 1024,
"frame_pts": 0,
"timestamp": 1745214270737,
"frame_image": "",
"algo_task": "1031",
"results": [
{
"algo_type": "1031",
"score": 0.983612060546875
}
],
"detect_objects": []
}
}
静默活体用于验证用户的身份,确保是真人而不是照片、视频或3D面具等非活体对象。
| 日期 | 版本 | 修订内容 |
|---|---|---|
| 2025-01-24 | v1.6.5.6 | 初始化API文档 |
服务接口调用时需要严格遵循服务鉴权规则,服务调用鉴权规则请参见:开发指南 - 接口签名认证。
| error_code状态码 | 编码int值 | 状态描述 | 英文描述 |
|---|---|---|---|
| APP_ERR_OK | 0 | 正常状态 | ok |
| APP_ERR_COMM_FAILURE | 1001 | 失败 | General Failed |
| APP_ERR_COMM_INNER | 1002 | 内部错误 | Internal error |
| APP_ERR_COMM_INVALID_POINTER | 1003 | 无效指针 | Invalid Pointer |
| APP_ERR_COMM_INVALID_PARAM | 1004 | 无效参数 | nvalid parameter |
| APP_ERR_COMM_UNREALIZED | 1005 | 未实现 | Not implemented |
| APP_ERR_COMM_OUT_OF_MEM | 1006 | 内存溢出 | Out of memory |
| APP_ERR_COMM_ALLOC_MEM | 1007 | 内存分配错误 | memory allocation error |
| APP_ERR_COMM_FREE_MEM | 1008 | 内存释放错误 | free memory error |
| APP_ERR_COMM_OUT_OF_RANGE | 1009 | 内存越界 | out of range |
| APP_ERR_COMM_NO_PERMISSION | 1010 | 无权限 | NO Permission |
| APP_ERR_COMM_TIMEOUT | 1011 | 超时 | Timed out |
| APP_ERR_COMM_NOT_INIT | 1012 | 未初始化 | Not initialized |
| APP_ERR_COMM_INIT_FAIL | 1013 | 初始化错误 | initialize failed |
| APP_ERR_COMM_INPROGRESS | 1014 | 操作正在进行中 | Operation now in progress |
| APP_ERR_COMM_EXIST | 1015 | 资源已存在 | Object; file or other resource already exist |
| APP_ERR_COMM_NO_EXIST | 1016 | 资源不存在 | Object; file or other resource doesn't exist |
| APP_ERR_COMM_BUSY | 1017 | 资源在使用中 | Object; file or other resource is in use |
| APP_ERR_COMM_FULL | 1018 | 无可用资源 | No available Device or resource |
| APP_ERR_COMM_OPEN_FAIL | 1019 | 文件或资源打开失败 | Device; file or resource open failed |
| APP_ERR_COMM_READ_FAIL | 1020 | 文件或资源读失败 | Device; file or resource read failed |
| APP_ERR_COMM_WRITE_FAIL | 1021 | 文件或资源写失败 | Device; file or resource write failed |
| APP_ERR_COMM_DESTORY_FAIL | 1022 | 文件或资源释放失败 | Device; file or resource destory failed |
| APP_ERR_COMM_EXIT | 1023 | 数据流结束,退出程序 | End of data stream; stop the application |
| APP_ERR_COMM_CONNECTION_CLOSE | 1024 | 连接断开 | Out of connection; Communication shutdown |
| APP_ERR_COMM_CONNECTION_FAILURE | 1025 | 连接失败 | connection fail |
| APP_ERR_COMM_STREAM_INVALID | 1026 | 无效流 | ACL stream is null pointer |
| APP_ERR_COMM_REGION_ERROR | 1027 | 区域校验失败 | region error |
| APP_ERR_COMM_DECODE_FAIL | 1028 | 图片解码失败 | Image decode fail |
| APP_ERR_COMM_MODELINIT_FAIL | 1029 | 模型初始化失败 | Model init fail |
| APP_ERR_COMM_MODELINFER_FAIL | 1030 | 模型推理失败 | Model infer fail |
| APP_ERR_COMM_PARAM_FAILURE | 1031 | 参数校验失败 | param check fail |
| APP_ERR_STREAMPULLER_OPEN_FAIL | 2001 | 拉流模块 | Open input stream failed |
| APP_ERR_STREAMPULLER_STREAMINFOFIND_FAIL | 2002 | 流打开失败 | Find stream information failed |
| APP_ERR_STREAMPULLER_EOF | 2003 | 查找流信息失败 | Stream if EOF |
| APP_ERR_STREAMPULLER_READFRAME_FAIL | 2004 | 流结束 | Stream read error frame |
| APP_ERR_STREAMPULLER_REOPEN_FAIL | 2005 | 重新打开流失败 | Reopen input stream failed |
| APP_ERR_STREAMPULLER_STREAMFIND_FAIL | 2006 | 查找视频channel失败 | Find no video stream |
| APP_ERR_STREAMPULLER_STREAMFORMAT_ERROR | 2007 | 不支持的视频格式 | Stream is unsupported video format |
| APP_ERR_VIDEODECODER_BASE | 2020 | 解码模块 | For Videodecoder |
| APP_ERR_VIDEODECODER_CREATE_FAIL | 2021 | 创建解码器失败 | Create MxBase::VideoDecoder Exception |
| APP_ERR_VIDEODECODER_UNSUPPORT_FORMAT | 2022 | 不支持的视频格式 | Stream is unsupported video format |
| APP_ERR_VIDEODECODER_DECODE_FAIL | 2023 | 视频解码失败 | decode fail |
| APP_ERR_CONFIG_BASE | 2040 | 参数配置 | For modulebase |
| APP_ERR_CONFIG_ADD_FAIL | 2041 | 添加参数失败 | Add new algo config failed |
| APP_ERR_CONFIG_UPDATE_FAIL | 2042 | 更新参数失败 | update config failed |
| APP_ERR_CONFIG_DELETE_FAIL | 2043 | 删除参数失败 | delete config failed |
| APP_ERR_QUEUE_EMPTY | 5001 | 队列为空 | Queue: empty queue |
| APP_ERR_QUEUE_STOPED | 5002 | 队列已停止 | Queue: queue stoped |
| APP_ERR_QUEUE_FULL | 5003 | 队列满 | Queue: full queue |
通用状态码请参考【状态码】中的【网关认证】
{
"code": 1019,
"data": {
"taskId": "task_1",
"algoTasks": [{
"algoTask": 1031,
"algoConfig": {
"silentface": {
"algoType": 1031
}
}
}],
"imageList": [{
"image": "yourImageBase64"
}]
}
}
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONUtil;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/** 主类,用于发起HTTP请求并处理响应 */
public class Example {
public static void main(String[] args) {
example();
}
/**
* 方法中使用到的 JSONUtil、HttpRequest、HttpResponse均来自Hutool工具类。
* 具体maven依赖为:
*
* cn.hutool
* hutool-all
* 5.8.29
*
*/
public static void example() {
try {
String url = "算法调用地址";
// 设置请求头
Map headers = new HashMap();
//调用鉴权
headers.put("Content-Type", "application/json");
headers.put("X-APP-ID", "yourAppId");
headers.put("Authorization", "yourAuthorization");
// 创建请求对象
Map request = new HashMap();
request.put("code", 1019);
Map data = new HashMap();
data.put("taskId", "task_1");
Map algoTask = new HashMap();
algoTask.put("algoTask", 1031);
Map algoConfig = new HashMap();
Map silentface = new HashMap();
silentface.put("algoType", 1031);
algoConfig.put("silentface", silentface);
algoTask.put("algoConfig", algoConfig);
data.put("algoTasks", Arrays.asList(algoTask));
Map image = new HashMap();
image.put("image", "yourImageBase64");
data.put("imageList", Arrays.asList(image));
request.put("data", data);
// 将请求对象转换为JsonNode
String requestString = JSONUtil.toJsonStr(request);
// 发起HTTP请求
HttpResponse response =
HttpRequest.post(url)
.headerMap(headers, true)
.body(requestString)
.execute();
// 输出响应结果
System.out.println(response.body());
} catch (Exception e) {
e.printStackTrace();
}
}
}
import json
import hashlib
import hmac
import time
import re
import urllib.parse
import requests
import warnings
from datetime import datetime
import logging
# 配置日志,设置日志级别为INFO,并指定日志格式
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
# 配置环境变量
X_APP_ID = "yourAppId"
AUTHORIZATION = "yourAuthorization"
# URL 和请求数据
url = "算法调用地址" # 请求的URL
request_data = {
"code": 1019,
"data": {
"taskId": "task_1",
"algoTasks": [{
"algoTask": 1031,
"algoConfig": {
"silentface": {
"algoType": 1031
}
}
}],
"imageList": [{
"image": "yourImageBase64"
}]
}
}
# 构建请求头
headers = {
"Content-Type": "application/json",
"X-APP-ID": X_APP_ID,
"Authorization": AUTHORIZATION
}
def timeSimple(timestamp):
# 将时间戳转换为HH:MM:SS格式的时间字符串
dt_object = datetime.fromtimestamp(timestamp)
formatted_time = dt_object.strftime("%H:%M:%S")
return formatted_time
def send_request(url):
try:
start_time = time.time()
logging.info(f"请求路径: {url}")
logging.info(f"开始发送: {timeSimple(start_time)}")
with requests.post(
url, json=request_data, headers=headers, stream=True, verify=False
) as response:
first_packet_time = None
if response.status_code == 200:
logging.info(f"接受到返回: {timeSimple(time.time())}")
for chunk in response.iter_content(chunk_size=1024):
if chunk:
if first_packet_time is None:
first_packet_time = time.time()
logging.info(
f"Received chunk: {timeSimple(time.time())} {chunk.decode('utf-8')}"
)
end_time = time.time()
logging.info(f"Time to first byte (TTFB): {first_packet_time - start_time:.3f} seconds")
logging.info(f"Request completed in {end_time - start_time:.3f} seconds")
else:
logging.error(f"Request failed with status code {response.status_code}")
except Exception as e:
logging.error(f"An error occurred: {e}")
# 发送请求
send_request(url)
logging.info(f"headers = {headers}")