人像抠图
描述
本接口用于图片内人像抠取
接口鉴权
接口地址
【POST】https://open-api.gaoding.com/api/call/mattingportrait
请求头(request header)
字段 | 类型 | 是否必填 | 字段描述 |
app_id | string | 是 | 应用ID,获取方式:应用列表 -> 应用详情 -> APP ID |
请求体(request body)
字段 | 类型 | 是否必填 | 字段描述 |
url | string | 二个必填一个 优先级:url>file_base64 | 原图url,支持JPG、PNG格式, 仅保留1个月,请及时转储 (无文件大小限制) |
file_base64 | string | 原图的base64码 (最大支持3M文件) | |
result_type | string | 否 | 结果返回类型: 枚举值:url,base64 默认url |
use_face | number | 否 | 是否获取人脸关键点:0-否,1-是,默认0 |
person_attribute | number | 否 | 是否人像详细属性(含帽子/眼镜/首饰识别,人脸肩膀完整性、角度等):0-否,1-是 (person_attribute为1的话use_face也必须为1)默认0 |
use_compress | number | 否 | 是否压缩:0-否,1-是,默认为0 |
use_hair | number | 否 | 是否使用头发分割、融合算法 1:开启 0:关闭 |
fg_flag | number | 否 | 是否使用前景预测优化算法(前景预测算法会优化抠图结果,也就不再需要使用头发分割、融合算法) 0-否, 1-是 默认1 |
请求体示例(url):
{
"url": "https://matting-batch.dancf.com/cloths/20220825_143743_gaoding_imagematting_human.jpg",
"use_face": 1,
"person_attribute": 1
}
请求体示例(base64):
{
"file_base64": "图片的base64编码",
"use_face": 1,
"person_attribute": 1
}
响应体(response body)
字段 | 类型 | 是否必存在 | 字段描述 |
result | string | 是 | url入参:结果图url,返回PNG格式,仅保留1个月,请及时转储。 base64入参:返回图片base编码 |
attribute | object | 否 | 人像的属性参数(use_face为1 会返回) |
attribute.face_count | number | 否 | 人脸识别个数 |
attribute.face_ponumber | string | 否 | 人脸关键点信息 |
attribute.face_rect | string | 否 | 人脸框坐标, 顺序xywh |
attribute.top_ponumber | string | 否 | 头顶坐标 |
attribute.wear_glasses | number | 否 | 人像属性, 是否戴眼镜: 0-否, 1-是 |
attribute.wear_hat | number | 否 | 人像属性, 是否戴帽子: 0-否, 1-是 |
attribute.jewelry | number | 否 | 人像属性, 是否戴首饰: 0-否, 1-是 |
attribute.body_complete | number | 否 | 人像属性, 上半身是否完整: 0-否, 1-是 |
attribute.definition | number | 否 | 人像属性, 人脸清晰度: 0-清晰, 1-模糊 |
attribute.face_angle | number | 否 | 人像属性, 人脸左右歪斜: 0-正面, 1-左歪, 2-右歪 |
attribute.face_complete | number | 否 | 人像属性, 人脸是否完整: 0-否, 1-是 |
attribute.face_ratio | number | 否 | 人像属性, 人脸占画面比例: 0-正常, 1-偏小, 2-偏大 |
attribute.face_side | number | 否 | 人像属性, 左右侧脸: 0-正面, 1-左侧, 2-右侧 |
attribute.face_updown | number | 否 | 人像属性, 上下抬脸: 0-正面, 1-上抬, 2-下低 |
attribute.shoulder_complete | number | 否 | 人像属性, 肩膀是否完整: 0-否, 1-是, 2-不确定 |
attribute.shoulder_parallel | number | 否 | 人像属性, 肩膀平齐: 1-双肩平齐, 2-左高右低, 3-左低右高, 4-不确定 |
响应示例1(模拟正常请求:url入参):
http_status:200
response body:
{
"result": "https://matting-batch.dancf.com/dev/api/035cafcab0cce4a5-20220825153613724.png",
"face_count": 1,
"image_pos": "364 360,366 398,370 434,378 470,390 504,410 534,436 562,468 582,502 588,538 582,568 562,592 534,612 504,626 470,632 434,640 400,642 362,384 338,402 322,428 318,454 320,476 330,522 330,546 320,572 318,598 322,618 338,502 366,502 390,502 414,502 440,476 458,488 462,502 464,514 462,528 458,412 366,428 358,446 358,464 374,446 376,426 374,538 374,556 360,574 358,590 366,576 376,558 376,452 498,470 490,490 484,502 488,514 484,534 490,552 498,534 516,516 524,502 526,488 524,470 516,458 500,490 502,502 504,514 502,544 500,514 502,502 504,488 502,",
"top_ponumber": 104,
"attribute": {
"face_count": 1,
"face_ponumber": "364 360,366 398,370 434,378 470,390 504,410 534,436 562,468 582,502 588,538 582,568 562,592 534,612 504,626 470,632 434,640 400,642 362,384 338,402 322,428 318,454 320,476 330,522 330,546 320,572 318,598 322,618 338,502 366,502 390,502 414,502 440,476 458,488 462,502 464,514 462,528 458,412 366,428 358,446 358,464 374,446 376,426 374,538 374,556 360,574 358,590 366,576 376,558 376,452 498,470 490,490 484,502 488,514 484,534 490,552 498,534 516,516 524,502 526,488 524,470 516,458 500,490 502,502 504,514 502,544 500,514 502,502 504,488 502,",
"face_rect": "364 217 270 371,",
"top_ponumber": 104,
"wear_glasses": 0,
"wear_hat": 0,
"wear_jewelry": 0,
"body_complete": 1,
"definition": 0,
"face_angle": 0,
"face_complete": 1,
"face_ratio": 0,
"face_side": 0,
"face_updown": 0,
"shoulder_complete": 1,
"shoulder_parallel": 1
}
}
响应示例2(模拟正常请求:base64入参):
http_status:200
response body:
{
"result": "图片的base64编码",
"face_count": 1,
"image_pos": "364 360,366 398,370 434,378 470,390 504,410 534,436 562,468 582,502 588,538 582,568 562,592 534,612 504,626 470,632 434,640 400,642 362,384 338,402 322,428 318,454 320,476 330,522 330,546 320,572 318,598 322,618 338,502 366,502 390,502 414,502 440,476 458,488 462,502 464,514 462,528 458,412 366,428 358,446 358,464 374,446 376,426 374,538 374,556 360,574 358,590 366,576 376,558 376,452 498,470 490,490 484,502 488,514 484,534 490,552 498,534 516,516 524,502 526,488 524,470 516,458 500,490 502,502 504,514 502,544 500,514 502,502 504,488 502,",
"top_ponumber": 104,
"attribute": {
"face_count": 1,
"face_ponumber": "364 360,366 398,370 434,378 470,390 504,410 534,436 562,468 582,502 588,538 582,568 562,592 534,612 504,626 470,632 434,640 400,642 362,384 338,402 322,428 318,454 320,476 330,522 330,546 320,572 318,598 322,618 338,502 366,502 390,502 414,502 440,476 458,488 462,502 464,514 462,528 458,412 366,428 358,446 358,464 374,446 376,426 374,538 374,556 360,574 358,590 366,576 376,558 376,452 498,470 490,490 484,502 488,514 484,534 490,552 498,534 516,516 524,502 526,488 524,470 516,458 500,490 502,502 504,514 502,544 500,514 502,502 504,488 502,",
"face_rect": "364 217 270 371,",
"top_ponumber": 104,
"wear_glasses": 0,
"wear_hat": 0,
"wear_jewelry": 0,
"body_complete": 1,
"definition": 0,
"face_angle": 0,
"face_complete": 1,
"face_ratio": 0,
"face_side": 0,
"face_updown": 0,
"shoulder_complete": 1,
"shoulder_parallel": 1
}
}
响应示例3(模拟参数非法请求):
http_status:400
response body:
{
"code": -10003,
"message": "InvalidArgsError"
}
错误码
HTTP状态码 | 业务错误码 | 含义 |
400 | -10003 | 参数非法 |
400 | -10024 | 通过指定的upload_address 上传的的时候失败 |
400 | -10001 | 下载失败,可能是用户传的url非法,或者网络异常等原因导致下载失败 |
400 | -10002 | 解码图片失败,可能是某些格式比较特殊的图片暂时还不支持,或者图片url下载下来根本不是图像数据 |
400 | -10007 | 图片数据过大,无法处理 |
500 | 服务器错误 | |
422 | 接口入参错误 |