请求方式:POST (HTTPS)
请求地址:
https://open.welink.huaweicloud.com/api/aiservice/v1/ocr/general-table
认证方式: access_token,请参考获取access_token
请求头部:
Content-Type: application/json
x-wlk-Authorization: access_token
请求参数
{
"image":"/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgAAAA..."
}
请求参数说明
参数 | 必填 | 参数类型 | 说明 |
---|---|---|---|
image | 是 | String | 图像数据,base64编码,要求base64编码后大小不超过10MB。图片最小边不小于15像素,最长边不超过4096像素,支持JPEG/JPG/PNG/BMP/TIFF格式。 |
returnConfidence | 否 | Boolean | 是否返回置信度的开关,可选值包括: true:返回置信度 false:不返回置信度 如果无该参数,系统默认不返回置信度。如果输入参数不是Boolean类型,则会报非法参数错误。 |
请求示例
curl -X POST \
'https://open.welink.huaweicloud.com/api/aiservice/v1/ocr/general-table' \
-H 'Accept-Charset: UTF-8' \
-H 'Content-Type: application/json' \
-H 'x-wlk-Authorization: access_token' \
-d '{"image":"/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgAAAA..."}'
响应格式说明
返回结果 正常返回结果
{
"code": "0",
"data": {
"words_region_count": 2,
"words_region_list": [
{
"type": "text",
"words_block_count": 1,
"words_block_list": [
{
"words":"文字区域识别文字块1",
"confidence": 0.9991
}
]
},
{
"type": "table",
"words_block_count": 2,
"words_block_list": [
{
"words":"表格区域识别文字块1",
"confidence": 0.9942,
"rows":[
0
],
"columns":[
0
]
},
{
"words":"表格区域识别文字块2",
"confidence": 0.9140,
"rows":[
0
],
"columns":[
1,
2
]
}
]
},
]
}
"error": "",
"message": "ok"
}
异常返回结果
OCR识别失败响应示例
{ "code": "58105", "data": null, "error": "Recognize Failed", "message": "OCR service call exception" }
Token验证失败响应示例
{ "code": "58401", "data": null, "error": "Failed to verify the token.", "message": "Login authentication failed." }
返回参数说明
参数 | 必选 | 参数类型 | 说明 |
---|---|---|---|
code | 是 | String | 错误码 |
message | 是 | String | 调用成功时为"ok"。调用失败时的错误信息。 |
data | 是 | Object | 调用成功时表示调用结果,详见data数据结构。调用失败时为null。 |
error | 是 | String | 错误信息。 |
- data 数据结构
参数 | 必选 | 参数类型 | 说明 |
---|---|---|---|
words_region_count | 是 | Integer | 文字区域数目。 |
words_region_list | 是 | Array [words_region] | 文字区域识别结果列表,输出顺序从左到右,先上后下。详见words_region数据结构 |
- words_region 数据结构
参数 | 必选 | 参数类型 | 说明 |
---|---|---|---|
type | String | 是 | 文字识别区域类型。 text:文本识别区域 table:表格识别区域 |
words_block_count | 是 | String | 子区域识别文字块数目。 |
words_block_list | 是 | Array [words_block] | 子区域识别文字块列表,输出顺序从左到右,先上后下。详见words_block数据结构 |
- words_block 数据结构
参数 | 必选 | 参数类型 | 说明 |
---|---|---|---|
words | 是 | String | 文字块识别结果。 |
rows | 否 | Array [Integer] | 文字块占用的行信息,编号从0开始,列表形式,数据类型为Integer。仅在表格区域内有效,即type字段为"table"时该字段有效。 |
columns | 否 | Array [Integer] | 文字块占用的列信息,编号从0开始,列表形式,数据类型为Integer。仅在表格区域内有效,即type字段为"table"时该字段有效。 |
confidence | 否 | Float | 字段的平均置信度,置信度越大,表示本次识别的对应字段的可靠性越高,在统计意义上,置信度越大,准确率越高。置信度由算法给出,不直接等价于对应字段的准确率。 |
错误码说明
错误码 | 说明 |
---|---|
0 | 成功。 |
58401 | 无权限。 |
58402 | 非法参数异常。 |
58500 | 服务异常。 |
58001 | OCR服务异常。 |