Skip to content

任务:智能抠图

简洁描述:使用抠图接口提取图像前景,并返回处理后的图片或蒙版。


概览

  • 请求方法:POST
  • 路径:/task/pic/segmentation
  • 内容类型:multipart/form-data

认证方式

  • Header:Authorization: Bearer <token>

请求示例

表单参数

参数类型必填说明
image_filefile源图像文件(二进制),与 image_url 二选一
image_urlstring源图像 URL,与 image_file 二选一
syncinteger是否等待结果就绪:0=异步(默认),1=同步
typestring前景类型:personobjectstamp,为空则自动检测
output_typeinteger返回类型:1=图片+蒙版、2=仅图片、3=仅蒙版(默认2
cropinteger是否裁剪到目标边缘:0=原图大小、1=裁剪
formatstring图片格式:png=透明图、jpg=白底图(默认png
bg_colorstringJPG 背景色,支持十六进制颜色码,例如 ffffff
callback_urlstring回调通知地址

curl 示例

bash
curl -X POST "https://api.gpt.ge/task/pic/segmentation" \
  -H "Authorization: Bearer sk-xxxx" \
  -F "image_url=https://example.com/image.png" \
  -F "sync=1" \
  -F "output_type=2" \
  -F "format=png"

JavaScript (fetch) 示例

javascript
const formData = new FormData();
formData.append('image_url', 'https://example.com/image.png');
formData.append('sync', '1');
formData.append('output_type', '2');
formData.append('format', 'png');

fetch('https://api.gpt.ge/task/pic/segmentation', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer sk-xxxx'
  },
  body: formData
}).then(r => r.json()).then(console.log);

Python(requests)示例

python
import requests

url = 'https://api.gpt.ge/task/pic/segmentation'
headers = {
    'Authorization': 'Bearer sk-xxxx'
}

files = {
    'image_url': (None, 'https://example.com/image.png')
}
data = {
    'sync': '1',
    'output_type': '2',
    'format': 'png'
}

response = requests.post(url, headers=headers, files=files, data=data)
print(response.json())

返回示例(200)

json
{
  "status": 200,
  "data": {
    "completed_at": 1742670627,
    "created_at": 1742670626,
    "download_time": 488,
    "err_info": "",
    "foreground_rect": {
      "x": 133,
      "y": 110,
      "width": 604,
      "height": 952
    },
    "image": "https://wxtechsz.oss-cn-shenzhen.aliyuncs.com/tasks/output/segmentation/3b950563-e53f-4036-a581-5ac04d0829b3-image.png",
    "image_height": 1152,
    "image_width": 864,
    "output_type": 2,
    "processed_at": 1742670626,
    "progress": 100,
    "result_type": "object",
    "return_type": 1,
    "state": 1,
    "state_detail": "Complete",
    "task_id": "3b950563-e53f-4036-a581-5ac04d0829b3",
    "time_elapsed": 384.54998779296875,
    "type": "auto"
  }
}

注意:该接口使用 multipart/form-data 上传图片,建议优先使用 image_urlimage_file 中的一种方式提交图像。