图像内容理解(公测)
更新时间:2024-07-17
接口描述
该请求用于图像内容理解,支持输入图片和提问信息,可对输入图片进行理解,输出对图片的一句话描述,同时可针对图片内的主体/文字等进行检测与识别,支持返回图片内多主体/文字的内容、位置等信息。图像内容理解服务涉及 2 个子接口,分别为:
- 图像内容理解-提交请求:支持传入图片、提问等参数,创建图像内容理解任务,该接口会返回任务ID。
- 图像内容理解-获取结果:在任务成功创建后,支持传入任务ID,查看任务处理的状态、获取处理完成后返回的结果。
图像内容理解-提交请求
在线调试
您可以在 示例代码中心 中调试该接口,可进行签名验证、查看在线调用的请求内容和返回结果、示例代码的自动生成。
请求示例
HTTP 方法:POST
请求URL: https://aip.baidubce.com/rest/2.0/image-classify/v1/image-understanding/request
URL参数:
参数 | 值 |
---|---|
access_token | 通过API Key和Secret Key获取的access_token,参考“Access Token获取” |
Header如下:
参数 | 值 |
---|---|
Content-Type | application/json |
Body中放置请求参数,要求使用json格式的结构体来描述一个请求的具体内容,参数详情如下:
请求参数
参数 | 是否必选 | 类型 | 可选值范围 | 说明 |
---|---|---|---|---|
image | 和 url 二选一 | string | - | 图片数据,base64 编码后进行 urlencode,要求 base64 编码和 urlencode 后大小不超过 10M,最短边至少 64px,最长边最大 8192px,支持 jpg/jpeg/png 格式 优先级:image > url,当 image 字段存在时,url 字段失效 注意: 超过 4096px 的图片,将被自动等比例压缩至 4096px 进行处理,压缩后会影响处理效果 |
url | 和 image 二选一 | string | - | 图片完整 url,url 长度不超过 1024 字节,要求 base64 编码和 urlencode 后大小不超过 4M,最短边至少 64px,最长边最大 8192px,支持 jpg/jpeg/png 格式优先级:image > url,当 image 字段存在时,url 字段失效 注意: 超过 4096px 的图片,将被自动等比例压缩至 4096px 进行处理,压缩后会影响处理效果请注意关闭URL防盗链 |
question | 是 | string | - | 提问信息,如“这张图片里有什么?”、“这张图片里有几只鸟”限制 100 个字符之内 |
output_CHN | 否 | bool | true/false | 是否以中文输出描述 description 和拼接语句 description_to_llm ,可选值包括:- true:以中文输出- false:不以中文输出,默认为 false |
返回参数
字段 | 类型 | 说明 |
---|---|---|
log_id | uint64 | 唯一的log id,用于问题定位 |
result | object | 返回结果列表 |
+ task_id | string | 该请求生成的task_id,后续使用该task_id获取识别结果 |
返回示例
{
"log_id": 1749362025959261144,
"result":{
"task_id":"1749357426042159725",
},
}
图像内容理解-获取结果
在线调试
您可以在 示例代码中心 中调试该接口,可进行签名验证、查看在线调用的请求内容和返回结果、示例代码的自动生成。
请求示例
HTTP 方法:POST
请求URL:https://aip.baidubce.com/rest/2.0/image-classify/v1/image-understanding/get-result
URL参数:
参数 | 值 |
---|---|
access_token | 通过API Key和Secret Key获取的access_token,参考“Access Token获取” |
Header如下:
参数 | 值 |
---|---|
Content-Type | application/json |
Body中放置请求参数,要求使用json格式的结构体来描述一个请求的具体内容,参数详情如下:
请求参数
参数 | 是否必选 | 类型 | 可选值范围 | 说明 |
---|---|---|---|---|
task_id | 是 | string | - | 调用提交请求接口时,返回的task_id |
返回参数
字段 | 类型 | 说明 |
---|---|---|
log_id | uint64 | 唯一的log id,用于问题定位 |
result | object | 返回结果列表 |
+ task_id | string | 该结果对应请求的task_id |
+ ret_code | int | 识别状态,0:处理成功;1:处理中;若发生错误,将返回其他错误码,详情可参考 图像识别-错误码 |
+ ret_msg | string | 识别状态信息:sucess:处理成功;processing:处理中;若发生错误,将返回其他错误信息,详情可参考 图像识别-错误码 |
+ description | string | 针对图片的一句话描述,当 output_CHN= true 时,该字段输出为中文 |
+ description_to_llm | string | 拼接一句话描述、OCR 及图像识别结果、提问信息后的语句,将该语句输入大模型后,大模型将基于图像内容与提问,给出相应答案当 output_CHN= true 时,该字段输出为中文;当 output_CHN= false 时,该字段输出为中英混合 |
+ subject_result | array | 图片内主体检测的信息 |
++ name | string | 图片主体标签 |
++ location | object | 图片内主体的检测框位置信息 |
+ classify_result | array | 图片内目标分类的信息 |
+ ocr_result | array | 当图片中存在文字时,该参数有返回 |
++ word | string | 文字识别结果字符串 |
++ rect | array | 文字识别结果位置信息 |
+++ left | uint32 | 位置的长方形左上顶点的水平坐标 |
+++ top | uint32 | 位置的长方形左上顶点的垂直坐标 |
+++ width | uint32 | 位置的长方形的宽度 |
+++ height | uint32 | 位置的长方形的高度 |
返回示例
{
"result": {
"task_id": "1749362988988414037",
"ret_code": 0,
"ret_msg": "success",
"description_to_llm": "用户上传的图像,经过前期模型分析存在以下信息:图中植物是:'向日葵整个图像内容可以表述为:'The image showcases a vibrant sunflower with its bright yellow petals and a darkbrown center,standing tall against a clear blue sky.The sunflower is positioned prominently in the foreground,with its leaves spreading out at the bottom.'。请根据上述分析后资料,回答如下问题:这个图里的有什么,注意不要复述提供的资料内容",
"description": "The image showcases a vibrant sunflower with its bright yellow petals and a darkbrown center,standing tall against a clear blue sky.The sunflower is positioned prominently in the foreground,with its leaves spreading out at the bottom.",
"classify_result": [
"植物-向日葵"
],
"ocr_result": [
{
"rect": {
"left": 19,
"top": 13,
"width": 108,
"height": 16
},
"word": "精品图片汇"
},
{
"rect": {
"left": 71,
"top": 115,
"width": 27,
"height": 12
},
"word": "向日葵"
}
],
"subject_result": [
{
"name": "sunflower",
"location": {
"top": 110,
"left": 52,
"width": 255,
"height": 130
}
}
],
},
"log_id": 1749363745970627082
}