提交商品图智能抠图任务
1. 接口地址
https://www.hidreamai.com/api-pub/gw/v3/image/segment/sync
2. 请求方式
POST
3. 请求参数
Header
参数 | 类型 | 是否必填 | 说明 |
---|---|---|---|
Authorization(用户授权) | string | 是 | 客户授权Token |
Content-Type(传递内容) | string | 是 | 使用json传参 |
X-accept-language | string | 否 | 语言偏好,支持['en', 'zh'],en:英文,zh:中文,默认为"zh" |
API-User-ID | string | 否 | 用户唯一标识 |
Body
参数 | 类型 | 是否必填 | 说明 |
---|---|---|---|
image | string | 是 | 待分割的图片,支持传入图片的base64值/URL地址 |
version | string | 否 | 模型版本,默认为"v1",可选范围为{"v1"} |
request_id | string | 否 | 请求的ID,默认为"" |
说明:
curl示例
curl -H 'Authorization: Bearer {USER_Authorization}' \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"image": "https://storage-cdn.hidreamai.com/image/p_ead9e67c-2d1e-11ef-b7c2-6234fd3f7cde_wm.jpg?width=512",
"version": "v1",
}' \
-v 'https://www.hidreamai.com/api-pub/gw/v3/image/segment/sync'
Python示例
import requests
import json
import uuid
USER_Authorization = <token>
# 请求头
headers = {
'Authorization': f'Bearer {USER_Authorization}',
'Content-Type': 'application/json',
'API-User-ID': '' # 可选的用户唯一标识
}
# 请求体参数
data = {
"image": "https://storage-cdn.hidreamai.com/image/p_ead9e67c-2d1e-11ef-b7c2-6234fd3f7cde_wm.jpg?width=512",
"version": "v1",
}
# 发送POST请求
url = 'https://www.hidreamai.com/api-pub/gw/v3/image/segment/sync'
response = requests.post(url, headers=headers, data=json.dumps(data))
# 处理响应
if response.status_code == 200:
if response.json()['code'] == 0:
task_id = response.json()['result']['task_id']
print(task_id)
else:
print(response.json()['message'])
else:
print(response.status_code)
4. 返回参数
参数 | 类型 | 说明 |
---|---|---|
code | int | 返回状态码 |
message | string | 返回状态信息 |
request_id | string | 本次请求的ID |
result | dict | 返回结果 |
其中返回结果 result字段具体为:
参数 | 类型 | 说明 |
---|---|---|
image | string | 分割的结果图片 |
示例:
{
"code":0,
"message":"Success",
"request_id":"ccfc092e-8430-11ee-97ff-f60f825045d5",
"result":{
"image":"https://storage-cdn.hidreamai.com/image/p_9e964714-3aa8-11ef-8359-a219be302849.png"
}
}