pp-structure v3
权限说明
调用本文API,需使用API Key鉴权方式。使用API Key鉴权调用API流程,具体调用流程,请查看 认证鉴权。
请求参数
输入文件。
图像文件或PDF文件,支持URL或Base64
- 单pdf文档:大小控制在 50MB 以内。对于超过 10 页的 PDF 文件,只有前 10 页的内容会被处理。
- 单图片image:大小控制在 10MB 以内。
模型名称:固定为pp-structurev3。
文件类型
0表示PDF文件,1表示图像文件。
若file为URL,可不传,将根据URL推断文件类型。
若file为base64,此字段为必传。
NMS 后处理
开启后,会自动移除重复或高度重叠的区域框。默认值为true。
是否返回可视化结果图以及处理过程中的中间图像等。默认为true。
- true:返回图像。
- false:不返回图像。
印章文本像素阈值
输出的概率图中,得分大于该阈值的像素点才会被认为是文字像素点。
默认0.2,取值范围:大于0。
文本检测像素阈值
输出的概率图中,得分大于该阈值的像素点才会被认为是文字像素点。
默认0.3,取值范围:大于0。
版面模型得分阈值
默认值:0.5,取值范围:[0.0, 1.0]
图片扭曲矫正
开启后,可以自动矫正扭曲图片,例如褶皱、倾斜等情况。默认值为false。
印章文本检测框阈值
检测结果边框内,所有像素点的平均得分大于该阈值时,该结果会被认为是文字区域。
默认值:0.6,取值范围:大于0。
印章文本检测的图像边长限制类型。支持min和max。默认值为min。
min表示保证图像最短边不小于sealDetLimitSideLen。max表示保证图像最长边不大于sealDetLimitSideLen。
文本检测框阈值
检测结果边框内,所有像素点的平均得分大于该阈值时,该结果会被认为是文字区域。
默认0.6,取值范围:大于0
文本检测的边长度限制类型。支持min和max,默认值为min。
min表示保证图像最短边不小于textDetLimitSideLen。max表示保证图像最长边不大于textDetLimitSideLen。
版面区域检测模型检测框的扩张系数
默认值:1.0,取值范围:大于0.0。
印章文本检测的扩张系数
使用该方法对文字区域进行扩张,该值越大,扩张的面积越大。默认值:0.5,取值范围:大于0。
印章文本识别阈值
得分大于该阈值的文本结果会被保留。默认值:0.0,取值范围:大于等于0。
文本检测的扩张系数
使用该方法对文字区域进行扩张,该值越大,扩张的面积越大。默认值:1.5,取值范围:大于0。
文本识别阈值
得分大于该阈值的文本结果会被保留。默认值:0.0,取值范围:大于等于0。
复杂版面处理
开启后,可以更好地识别报纸、杂志等排版复杂的文档内容,提高识别准确性。默认为true。
印章识别
开启后,可以识别文档中的印章内容。默认为false。
印章检测的图像边长限制
默认值:736,取值范围:大于0。
文本检测的图像边长限制
默认值:736,取值范围:大于0。
图表转表格
开启后,可以自动解析文档中的图表(如柱状图、饼图等)并转换为表格形式,方便查看和编辑数据。默认值:false。
表格识别
开启后,可以将文档中的表格转换为HTML或Markdown的结构化格式,若不开启,表格会保留为图片形式。默认为true。
公式识别
是否在推理时使用公式识别子产线,开启后,可以将数学公式转换为LaTeX代码;若不开启,公式会按普通文本识别。默认为true
文本行方向矫正
开启后,可以自动识别和矫正 0° 和 180° 的文本行。默认为false。
有线表格端到端预测br> 启用则不使用单元格检测模型,只使用表格结构识别模型。默认为false。
图片方向矫正
开启后,可以自动识别并矫正 0°、90°、180°、270°的图片。
默认值为false。
无线表格端到端预测
启用则不使用单元格检测模型,只使用表格结构识别模型。默认为false。
单元格识别模式br> 启用时会基于单元格预测结果对OCR检测结果进行切分和重识别,避免出现文字缺失情况。默认为true。
表格方向矫正
启用时当图像中的表格存在90°、180°、270°旋转时,能够将方向校正并正确完成表格识别。默认为true。
有线表转 HTML
启用则直接基于有线表单元格检测结果的几何关系构建HTML。默认为false。
无线表转 HTML
启用则直接基于无线表单元格检测结果的几何关系构建HTML。默认为false。
POST /v2/ocr/paddleocr HTTP/1.1
Host: qianfan.baidubce.com
Authorization: Bearer <API Key>
Content-Type: application/json
{
"model": "pp-structurev3",
"file": "https://example.com/sample.jpg",
"fileType": 1,
"useDocOrientationClassify": false,
"useDocUnwarping": false,
"useTextlineOrientation": false,
"useSealRecognition": false,
"useTableRecognition": true,
"useFormulaRecognition": true,
"useChartRecognition": false,
"useRegionDetection": true,
"layoutThreshold": 0.5,
"layoutNms": true,
"layoutUnclipRatio": 1,
"textDetLimitSideLen": 736,
"textDetLimitType": "min",
"textDetThresh": 0.3,
"textDetBoxThresh": 0.6,
"textDetUnclipRatio": 1.5,
"textRecScoreThresh": 0.0,
"sealDetLimitSideLen": 736,
"sealDetLimitType": "min",
"sealDetThresh": 0.2,
"sealDetBoxThresh": 0.6,
"sealDetUnclipRatio": 0.5,
"sealRecScoreThresh": 0.5,
"useWiredTableCellsTransToHtml": false,
"useWirelessTableCellsTransToHtml": false,
"useTableOrientationClassify": true,
"useOcrResultsWithTableCells": true,
"useE2eWiredTableRecModel": false,
"useE2eWirelessTableRecModel": false,
"visualize": true
}
示例代码
curl https://qianfan.baidubce.com/v2/ocr/paddleocr \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <API Key>" \
-d '{
"model": "pp-structurev3",
"file": "https://example.com/sample.jpg",
"fileType": 1,
"useDocOrientationClassify": false,
"useDocUnwarping": false,
"useTextlineOrientation": false,
"useSealRecognition": false,
"useTableRecognition": true,
"useFormulaRecognition": true,
"useChartRecognition": false,
"useRegionDetection": true,
"layoutThreshold": 0.5,
"layoutNms": true,
"layoutUnclipRatio": 1,
"textDetLimitSideLen": 736,
"textDetLimitType": "min",
"textDetThresh": 0.3,
"textDetBoxThresh": 0.6,
"textDetUnclipRatio": 1.5,
"textRecScoreThresh": 0.0,
"sealDetLimitSideLen": 736,
"sealDetLimitType": "min",
"sealDetThresh": 0.2,
"sealDetBoxThresh": 0.6,
"sealDetUnclipRatio": 0.5,
"sealRecScoreThresh": 0.5,
"useWiredTableCellsTransToHtml": false,
"useWirelessTableCellsTransToHtml": false,
"useTableOrientationClassify": true,
"useOcrResultsWithTableCells": true,
"useE2eWiredTableRecModel": false,
"useE2eWirelessTableRecModel": false,
"visualize": true
}'
返回响应
本次请求的唯一标识,可用于排查问题。
输出结果。
显示子属性
隐藏子属性
版面解析结果。
数组长度为1(对于图像输入)或实际处理的文档页数(对于PDF输入)。对于PDF输入,数组中的每个元素依次表示PDF文件中实际处理的每一页的结果。
显示子属性
隐藏子属性
显示子属性
隐藏子属性
处理后结果。
对象的predict方法生成结果的 JSON 表示中res字段的简化版本,其中去除了input_path和page_index字段。
显示子属性
隐藏子属性
配置 pp-structurev3 所需的模型参数。
显示子属性
隐藏子属性
是否启用文档预处理子产线。
是否启用版面检测模块。
是否开启图标识别功能。
是否在JSON中保存格式化后的markdown内容。
解析结果的列表,每个元素为一个字典,列表顺序为解析后的阅读顺序。
显示子属性
隐藏子属性
显示子属性
隐藏子属性
版面区域的边界框。
版面区域的标签,例如text, table等。
内容为版面区域内的内容。
显示子属性
隐藏子属性
版面区域的索引,用于显示版面排序结果。
版面区域的顺序,用于显示版面阅读顺序。
对于非排序部分,默认值为 null。
版面区域检测排序结果。
显示子属性
隐藏子属性
预测的目标框信息,一个字典列表。每个字典代表一个检出的目标。
显示子属性
隐藏子属性
显示子属性
隐藏子属性
类别 id。
类别名称
目标框置信度
目标框坐标,一个浮点数列表,格式为[xmin, ymin, xmax, ymax]。
显示子属性
隐藏子属性
输入的待预测图像的路径
如果输入是PDF文件,则表示当前是PDF的第几页
Markdown 结果
显示子属性
隐藏子属性
Markdown 文本
图像键值对
key:图片相对路径。
value:对应的图片链接,为JPEG格式,有效期 30 天。
显示子属性
隐藏子属性
暂无参数
当前页面第一个元素是否为段开始
当前页面最后一个元素是否为段结束
输出图片链接,为JPEG格式,有效期 30 天。
返回的预测结果是一个dict类型的数据。其中,键分别为layout_det_res、layout_order_res、layout_order_res 和preprocessed_img ,对应的值是Image.Image对象。
layout_det_res:用于显示版面区域检测的可视化图像layout_order_res:用于显示版面阅读顺序结果的可视化图像preprocessed_img:用于展示图像预处理的可视化图像
显示子属性
隐藏子属性
暂无参数
输入图片链接,为JPEG格式,有效期 30 天。
输入数据信息
显示子属性
隐藏子属性
输入文件类型,可为image或pdf
文件页数
当type=pdf时返回。
每页详细信息,包括宽高
当type=pdf时返回。
显示子属性
隐藏子属性
显示子属性
隐藏子属性
暂无参数
图片宽度
当type=image时返回。
图片高度
当type=image时返回。
{
"id": "as-abc123",
"result": {
"layoutParsingResults": [
{
"prunedResult": {
"model_settings": {
"use_doc_preprocessor": false,
"use_layout_detection": false,
"use_chart_recognition": false,
"format_block_content": true
},
"parsing_res_list": [
{
"block_label": "seal",
"block_content": "<div style=\"text-align: center;\"><img src=\"imgs/img_in_seal_box_35_23_189_184.jpg\" alt=\"Image\" width=\"20%\" /></div>\n",
"block_bbox": [
35,
23,
189,
184
],
"block_id": 0,
"block_order": null
},
{
"block_label": "seal",
"block_content": "<div style=\"text-align: center;\"><img src=\"imgs/img_in_seal_box_193_22_359_183.jpg\" alt=\"Image\" width=\"22%\" /></div>\n",
"block_bbox": [
193,
22,
359,
183
],
"block_id": 1,
"block_order": null
},
{
"block_label": "image",
"block_content": "<div style=\"text-align: center;\"><img src=\"imgs/img_in_image_box_553_23_712_183.jpg\" alt=\"Image\" width=\"21%\" /></div>\n",
"block_bbox": [
553,
23,
712,
183
],
"block_id": 2,
"block_order": null
}
],
"layout_det_res": {
"boxes": [
{
"cls_id": 15,
"label": "seal",
"score": 0.8285683393478394,
"coordinate": [
35.470794677734375,
23.19762420654297,
189.16064453125,
184.1409912109375
]
},
{
"cls_id": 15,
"label": "seal",
"score": 0.6310430765151978,
"coordinate": [
193.2289276123047,
22.45452880859375,
359.86468505859375,
183.8699951171875
]
},
{
"cls_id": 1,
"label": "image",
"score": 0.5838286876678467,
"coordinate": [
553.6396484375,
23.510948181152344,
712.8759765625,
183.05230712890625
]
}
]
}
},
"markdown": {
"text": "<div style=\"text-align: center;\"><img src=\"imgs/img_in_seal_box_35_23_189_184.jpg\" alt=\"Image\" width=\"20%\" /></div>\n\n\n<div style=\"text-align: center;\"><img src=\"imgs/img_in_seal_box_193_22_359_183.jpg\" alt=\"Image\" width=\"22%\" /></div>\n\n\n<div style=\"text-align: center;\"><img src=\"imgs/img_in_image_box_553_23_712_183.jpg\" alt=\"Image\" width=\"21%\" /></div>\n",
"images": {
"imgs/img_in_image_box_553_23_712_183.jpg": "http://***/pp-structurev3/sample1.jpeg",
"imgs/img_in_seal_box_193_22_359_183.jpg": "http://***/pp-structurev3/sample2.jpeg",
"imgs/img_in_seal_box_35_23_189_184.jpg": "http://***/pp-structurev3/sample3.jpeg"
},
"isStart": true,
"isEnd": true
},
"outputImages": {
"layout_det_res": "http://***/pp-structurev3/sample1.jpeg",
"layout_order_res": "http://***/pp-structurev3/sample2.jpeg",
"overall_ocr_res": "http://***/pp-structurev3/sample3.jpeg",
"region_det_res": "http://***/pp-structurev3/sample4.jpeg"
},
"inputImage": "http://***/pp-structurev3/sample.jpeg"
}
],
"dataInfo": {
"type": "image",
"width": 738,
"height": 214
}
},
"usage": {
"numPages": 1
}
}
错误码
如果调用失败并返回报错信息,请参见错误码进行解决。
公共错误码:查看公共错误码
本接口专有错误码如下:
| HTTP状态码 | 类型 | 错误码 | 错误信息 | 说明 |
|---|---|---|---|---|
| 500 | internal_error | ocr_internal_error | 返回的具体错误信息 | ocr内部错误 |
| 400 | invalid_request_error | invalid_argument | 返回的具体错误信息 | 参数报错 |
| 401 | invalid_request_error | invalid_model | No permission to use the model | model鉴权失败,该用户没有使用这个model的权限 |
| 500 | invalid_request_error | invalid_model | Model is empty | 未指定model参数 |
