请先登录
立即登录图层分解 API 文档
图层分解服务通过统一异步任务入口提供整图自动分解和指定区域分解能力。客户端准备图片并选择分解模式,通过 submit_task 提交异步任务,再通过 query_task 查询分层结果。
分解模式
| 模式 | pipeline_type | image_boxes | 适用场景 |
|---|---|---|---|
| 无框分解 | all |
必须为 [] |
不指定区域,由模型自动拆分整图 |
| 有框分解 | crop |
必须提供 1–20 个坐标框 | 按用户或调用方指定的区域拆分对象 |
两种模式使用同一个创建接口,沿用当前环境的图层分解单价。模式与框数组必须对应:all 不能携带非空框数组,crop 不能使用空数组。官网会根据是否画框自动选择模式。
请求地址
| 接口 | 方法 | 地址 |
|---|---|---|
| 图层分解(物体检测) | POST | https://api.research.360.cn/v1/object_detect |
| 图层分解(创建任务) | POST | https://api.research.360.cn/v1/submit_task |
| 图层分解(查询任务) | POST | https://api.research.360.cn/v1/query_task |
请求体使用 JSON。成功响应直接返回 task_id、status、output 等字段,读取时无需额外套用 data 层级。
服务能力
| 能力 | model | pipeline_type | image_boxes 限制 | steps 默认值 |
|---|---|---|---|---|
| 图层分解(无框) | reveal_layer |
all |
空数组 [] |
10 |
| 图层分解(有框) | reveal_layer |
crop |
1–20 个框 | 10 |
公共请求头
| Header | 类型 | 必填 | 说明 |
|---|---|---|---|
| accept | string | 是 | 固定为 application/json |
| Content-Type | string | 是 | 固定为 application/json |
| Authorization | string | 是 | Bearer your_key |
图片输入规范
input 为图片输入数组,每次提交一张图片,元素结构为 { "type": "input_image", "image_url": "data:image/png;base64,..." }。
图片支持 JPG、JPEG、PNG、BMP、WEBP。input[].image_url 可填写 HTTP/HTTPS 图片 URL,或完整的 Base64 Data URI,例如 data:image/png;base64,...;不能仅填写本地文件路径。
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
input[].type |
string | 是 | 固定为 input_image |
input[].image_url |
string | 是 | 图片 URL 或完整 Base64 Data URI,例如 https://example.com/image.png 或 data:image/jpeg;base64,... |
官网本地上传及图片 URL 均限制为 10MB。API Key 调用不设图片业务大小限制,URL 和 Base64 均支持;仍受网关请求体大小、读取超时及服务资源保护约束。Base64 会增大请求体,请根据网关上限控制编码后的请求大小。
使用图片 URL 时,请提供可读取的 HTTP/HTTPS 图片直链;使用 Base64 时,需携带与图片格式一致的 MIME 前缀,并将示例占位文本替换为真实编码。
坐标框规范
image_boxes 使用二维数组表示,格式为 [[x1, y1, x2, y2], [x3, y3, x4, y4]]。坐标以图片左上角为原点,x1,y1 为左上点,x2,y2 为右下点。
有框分解(crop)需提供 1–20 个框,坐标为原始图片上的像素坐标;左上角坐标非负,右下角必须大于左上角。无框分解(all)将 image_boxes 设为 []。
服务端按原图最长边等比缩放至 1024 像素的比例缩放画框;缩放后的每个框最短边须不小于 8 像素,否则报错。
输入框会经过 IoU(交并比)阈值为 0.8 的过滤,因此返回框的数量或顺序可能与输入不同。output.image_boxes 使用原图坐标,output.resized_image_boxes 使用前处理后的图片坐标;output.boxes_mapping_index 在服务返回时给出保留框与输入框的下标映射。
1. 图层分解(创建任务)
提交图层分解任务。服务端受理后返回 task_id,客户端使用该 ID 查询任务状态与输出结果。
Request Method
POST /v1/submit_task
Request Body
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model |
string | 是 | 图层分解固定为 reveal_layer |
request_id |
string | 否 | 本次请求的唯一标识,建议显式传入并保存;查询同一任务时保持一致 |
input |
object[] | 是 | 单张图片输入,image_url 支持 HTTP/HTTPS 图片 URL 或完整 Base64 Data URI,图片格式与大小限制同“图片输入规范” |
pipeline_type |
string | 是 | 分解模式:all 为无框整图分解,crop 为按框选区域分解,详见“分解模式” |
image_boxes |
number[][] | 是 | all 时为 [];crop 时为 1–20 个原图像素坐标框 [x1, y1, x2, y2],支持浮点数;左上角非负,且 x2 > x1、y2 > y1。按最长边缩放至 1024 后,框最短边须至少为 8 像素;服务端进行 IoU 过滤并返回下标映射,详见“坐标框规范” |
seed |
int | 否 | 不传时默认 42;范围 1 到 0xffffffffffffffff,0 无效;大整数须避免客户端 JSON 序列化丢失精度 |
steps |
int | 否 | 不传时默认 10;取值为 [10, 30] 范围内的 10 的整倍数,例如:10、20、30 |
input.image_url 支持 HTTP/HTTPS 图片 URL 或完整 Base64 Data URI,格式与大小规则见“图片输入规范”。调用方需显式传入分解模式与对应的 image_boxes:无框传 [],有框传 1–20 个坐标框。
请求示例
图层分解(创建任务:无框)
{
"model": "reveal_layer",
"request_id": "requestId-xxxxxxxx",
"input": [
{
"type": "input_image",
"image_url": "data:image/png;base64,REPLACE_WITH_IMAGE_BASE64"
}
],
"pipeline_type": "all",
"image_boxes": [],
"steps": 10,
"seed": 42
}
图层分解(创建任务:有框)
{
"model": "reveal_layer",
"request_id": "requestId-xxxxxxxx",
"input": [
{
"type": "input_image",
"image_url": "data:image/png;base64,REPLACE_WITH_IMAGE_BASE64"
}
],
"pipeline_type": "crop",
"image_boxes": [
[
20,
20,
200,
240
]
],
"steps": 10,
"seed": 42
}
Response
| 字段 | 类型 | 说明 |
|---|---|---|
model |
string | 同输入模型名(返回时) |
timestamp |
int | 返回时间戳,单位毫秒(返回时) |
task_id |
string | 服务端返回的任务 ID,查询时原样传入 |
request_id |
string | 本次请求标识(返回时) |
status |
string | 已受理时通常为 in_queue,尚不代表分解完成 |
message |
string | 成功提示或具体错误说明 |
response_status |
int | 0 表示本次请求正常,非 0 表示异常(返回时) |
output |
object | 创建阶段通常为空对象,图层结果通过查询接口获取 |
响应示例
{
"model": "reveal_layer",
"response_status": 0,
"message": "success",
"status": "in_queue",
"task_id": "taskId-xxxxxxxx",
"request_id": "requestId-xxxxxxxx",
"output": {}
}
2. 图层分解(查询任务)
根据 task_id 查询任务状态。任务完成后,响应中的 output 字段会返回独立图层、前景 mask 和处理后的辅助图片。
Request Method
POST /v1/query_task
Request Body
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model |
string | 是 | 图层分解固定为 reveal_layer |
task_id |
string | 是 | 创建任务接口返回的任务 ID,需要完全一致 |
request_id |
string | 否 | 使用创建该任务时的同一个请求标识;轮询和刷新恢复时保持不变,不要为每次查询生成新值 |
请求示例
{
"model": "reveal_layer",
"task_id": "taskId-xxxxxxxx",
"request_id": "requestId-xxxxxxxx"
}
Response
| 字段 | 类型 | 说明 |
|---|---|---|
model |
string | 同输入模型名(返回时) |
timestamp |
int | 返回时间戳,单位毫秒(返回时) |
task_id |
string | 查询的任务 ID |
request_id |
string | 请求标识(返回时) |
message |
string | 成功提示或具体错误说明 |
response_status |
int | 0 表示本次请求正常,非 0 表示异常(返回时) |
generation_time |
number | 任务生成耗时,单位秒(返回时) |
remaining_time |
number | 任务预计剩余处理时间,单位秒,仅作参考(返回时) |
status |
string | 任务状态,见下方状态说明 |
usage |
object | 用量信息,成功任务通过 total_tokens 返回实际计费用量 |
output |
object | 图层分解结果;未找到任务时仍为对象,layers_base 为空数组 |
billing |
object | 结算信息(返回时),包含结算状态及本次扣费等字段 |
charge_amount |
string | 本次实际扣费金额,单位元(返回时) |
status 状态
| 状态 | 说明 |
|---|---|
done |
任务处理结束,读取 output 中的结果 |
generating / running |
任务正在处理,可继续查询 |
in_queue |
任务正在排队,可继续查询 |
not_found |
任务未找到,请检查任务 ID、账户与所选环境 |
failed / timeout |
任务失败或超时,具体原因查看 message |
output 字段
| 字段 | 类型 | 说明 |
|---|---|---|
output.layers_base_count |
int | 基础图层数量,与 layers_base 数组长度一致;不要求等于框选数量 |
output.layers_base |
string[] | 基础图层的 HTTPS 图片 URL 列表,可能包含背景图层 |
output.layers_aug |
string[] | 增强图层的 HTTPS 图片 URL 列表 |
output.layers_fg_mask |
string[] | 前景 mask 图片 URL 列表,数量以实际返回为准 |
output.resized_image |
string | 前处理后缩放的原图 URL |
output.resized_bbox_image |
string | 前处理后带框图片 URL,用于核对提交区域 |
output.image_boxes |
number[][] | 原图像素坐标框,格式同创建任务的 image_boxes,顺序与 layers_base[1:] 对应;all 时由模型检测得出,crop 时返回经过 IoU 阈值 0.8 过滤后保留的输入框 |
output.resized_image_boxes |
number[][] | 前处理缩放后的坐标框,顺序与 layers_base[1:] 对应,须配合 resized_image 使用,不能直接绘制到原图上 |
output.boxes_mapping_index |
int[] | 服务返回时提供;第 i 项表示第 i 个保留框对应的原输入框下标,从 0 开始计数,用于关联过滤后的框与提交框 |
usage 字段
| 字段 | 类型 | 说明 |
|---|---|---|
usage.total_tokens |
int | 成功任务返回的实际计费用量 |
usage.prompt_tokens |
int | 服务返回时提供的辅助用量字段,不与 total_tokens 重复相加计费 |
响应示例
{
"model": "reveal_layer",
"response_status": 0,
"message": "success",
"status": "done",
"task_id": "taskId-xxxxxxxx",
"request_id": "requestId-xxxxxxxx",
"generation_time": 62,
"remaining_time": 0,
"usage": {
"prompt_tokens": 0,
"total_tokens": 10000
},
"output": {
"layers_base_count": 2,
"layers_base": [
"https://beijing2.xstore.qihu.com/example/background.png",
"https://beijing2.xstore.qihu.com/example/layer.png"
],
"layers_aug": [
"https://beijing2.xstore.qihu.com/example/background_aug.png",
"https://beijing2.xstore.qihu.com/example/layer_aug.png"
],
"layers_fg_mask": [
"https://beijing2.xstore.qihu.com/example/mask.png"
],
"resized_bbox_image": "https://beijing2.xstore.qihu.com/example/boxes.png",
"resized_image": "https://beijing2.xstore.qihu.com/example/input.png",
"image_boxes": [
[
20,
20,
200,
240
]
],
"resized_image_boxes": [
[
16,
16,
160,
192
]
],
"boxes_mapping_index": [
0
]
}
}
图层分解(物体检测)
检测图片中的可拆分对象,同步返回初始画框;无需轮询此接口。可调整检测框后通过创建任务接口进行分解。检测结果不保证覆盖所有对象,未检测到对象时可手动补框或使用无框分解。
Request Method
POST /v1/object_detect
Request Body
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
model |
string | 是 | 固定为 reveal_layer |
request_id |
string | 是 | 本次检测的唯一标识;重试同一次检测使用相同标识及相同参数,避免重复检测和扣费 |
input |
array | 是 | 单张图片,格式与大小规则见“图片输入规范” |
检测无需传入 pipeline_type、image_boxes、steps 或 seed;版本、product 及内部鉴权由服务端按环境配置。
请求示例
{
"model": "reveal_layer",
"request_id": "replace-with-a-unique-detect-request-id",
"input": [
{
"type": "input_image",
"image_url": "data:image/png;base64,REPLACE_WITH_IMAGE_BASE64"
}
]
}
Response
| 字段 | 类型 | 说明 |
|---|---|---|
request_id |
string | 本次检测请求标识 |
response_status |
number | 0 表示请求正常,非 0 表示异常 |
message |
string | 调用结果或具体错误信息 |
output |
object | 检测结果 |
output.image_boxes |
array | 原图坐标框,可编辑后作为有框分解的 image_boxes |
output.original_bbox_image |
string | 绘有检测框的辅助图片 URL(返回时) |
usage.total_tokens |
number | 本次检测实际 token 用量,用于按检测单价结算 |
画框使用 [x1, y1, x2, y2] 像素坐标。若返回缩放图片对应的框,应按对应图片尺寸换算到原图再提交;不可直接将缩放图坐标作为原图坐标。创建有框任务最多支持 20 个框,检测框超出时先删除多余画框。
响应示例
{
"model": "reveal_layer",
"request_id": "replace-with-a-unique-detect-request-id",
"response_status": 0,
"message": "success",
"output": {
"original_bbox_image": "https://beijing2.xstore.qihu.com/example/detected.png",
"image_boxes": [
[
20,
20,
200,
240
]
]
},
"usage": {
"prompt_tokens": 0,
"total_tokens": 100
}
}