印刷文字识别(多语种)
开发环境
开发环境
POST
http(s): //cn-east-1.api.xf-yun.com/v1/ocr
接口说明
印刷文字识别(多语种) demo java语言
印刷文字识别(多语种) demo python语言
内容 | 说明 |
---|---|
传输方式 | http[s] (为提高安全性,强烈推荐https) |
请求地址 | http(s): //cn-east-1.api.xf-yun.com/v1/ocr 注:服务器IP不固定,为保证您的接口稳定,请勿通过指定IP的方式调用接口,使用域名方式调用 |
请求行 | POST /v1/ocr HTTP/1.1 |
接口鉴权 | 签名机制,详情请参照下方鉴权说明 |
字符编码 | UTF-8 |
响应格式 | 统一采用JSON格式 |
开发语言 | 任意,只要可以向讯飞云服务发起HTTP请求的均可 |
适用范围 | 任意操作系统,但因不支持跨域不适用于浏览器 |
图片格式 | jpg, jpeg, png, bmp, webp, tiff |
图片大小 | 最小尺寸:1B, 最大尺寸:10485760B |
#鉴权说明
#鉴权方法
https://cn-east-1.api.xf-yun.com/v1/ocr?host=cn-east-1.api.xf-yun.com&date=Wed%2C+07+Dec+2022+08%3A18%3A43+GMT&authorization=YXBpX2tleT0iYTc0NjZkNmY1YTA5OWQzZWQzOTRiM2Y1OTc0NmNlZGIiLCBhbGdvcml0aG09ImhtYWMtc2hhMjU2IiwgaGVhZGVycz0iaG9zdCBkYXRlIHJlcXVlc3QtbGluZSIsIHNpZ25hdHVyZT0icDdKU3pQUzR3N0NWYndweEprQlBmSk1ueENheTlvbVh0Y1l1SHdhSS9DWT0i
参数 | 类型 | 必须 | 说明 | 示例 |
---|---|---|---|---|
host | string | 是 | 请求主机 | cn-east-1.api.xf-yun.com |
date | string | 是 | 当前时间戳,RFC1123格式("EEE, dd MMM yyyy HH:mm:ss z") | Wed, 07 Dec 2022 08:18:43 GMT |
authorization | string | 是 | 使用base64编码的签名相关信息(签名基于hamc-sha256计算) | 参考下方详细生成规则 |
服务端会对date进行时钟偏移检查,最大允许300秒的偏差,超出偏差的请求都将被拒绝。
在讯飞开放平台控制台,创建一个应用后打开印刷文字识别(多语种)页面可以获取,均为32位字符串。
2)参数authorization base64编码前(authorization_origin)的格式如下。
api_key="$api_key",algorithm="hmac-sha256",headers="host date request-line",signature="$signature"
signature 是使用加密算法对参与签名的参数签名后并使用base64编码的字符串,详见下方。
拼接的格式为(\n为换行符,’:’后面有一个空格):
host: $host\ndate: $date\n$request-line
请求url = "https://cn-east-1.api.xf-yun.com/v1/ocr"
date = "Wed, 07 Dec 2022 08:18:43 GMT"
host: cn-east-1.api.xf-yun.com
date: Wed, 07 Dec 2022 08:18:43 GMT
POST /v1/ocr HTTP/1.1
signature_sha=hmac-sha256(signature_origin,$apiSecret)
signature=base64(signature_sha)
APISecret = "apisecretXXXXXXXXXXXXXXXXXXXXXXX"
date = "Wed, 07 Dec 2022 08:18:43 GMT"
signature="p7JSzPS4w7CVbwpxJkBPfJMnxCay9omXtcYuHwaI/CY="
api_key="apikeyXXXXXXXXXXXXXXXXXXXXXXXXXX", algorithm="hmac-sha256", headers="host date request-line", signature="p7JSzPS4w7CVbwpxJkBPfJMnxCay9omXtcYuHwaI/CY="
authorization = base64(authorization_origin)
示例结果为:
authorization=YXBpX2tleT0iYTc0NjZkNmY1YTA5OWQzZWQzOTRiM2Y1OTc0NmNlZGIiLCBhbGdvcml0aG09ImhtYWMtc2hhMjU2IiwgaGVhZGVycz0iaG9zdCBkYXRlIHJlcXVlc3QtbGluZSIsIHNpZ25hdHVyZT0icDdKU3pQUzR3N0NWYndweEprQlBmSk1ueENheTlvbVh0Y1l1SHdhSS9DWT0i
#鉴权结果
HTTP Code | 说明 | 错误描述信息 | 解决方法 |
---|---|---|---|
401 | 缺少authorization参数 | {"message":"Unauthorized"} | 检查是否有authorization参数,详情见authorization参数详细生成规则 |
401 | 签名参数解析失败 | {“message”:”HMAC signature cannot be verified”} | 检查签名的各个参数是否有缺失是否正确,特别确认下复制的api_key是否正确 |
401 | 签名校验失败 | {“message”:”HMAC signature does not match”} | 签名验证失败,可能原因有很多。 1. 检查api_key,api_secret 是否正确。 2.检查计算签名的参数host,date,request-line是否按照协议要求拼接。 3. 检查signature签名的base64长度是否正常(正 常44个字节)。 |
403 | 时钟偏移校验失败 | {“message”:”HMAC signature cannot be verified, a valid date or x-date header is required for HMAC Authentication”} | 检查服务器时间是否标准,相差5分钟以上会报此错误 |
HTTP/1.1 403 Forbidden
Date: Mon, 30 Nov 2020 02:34:33 GMT
Content-Length: 116
Content-Type: text/plain; charset=utf-8
{
"message": "HMAC signature does not match, a valid date or x-date header is required for HMAC Authentication"
}
{
"category" : "mix6",
"pages" : [
{
"angle" : 359.08724975585938,
"exception" : 0,
"height" : 326,
"lines" : [
{
"angle" : 0,
"conf" : 0.98804998397827148,
"content" : "荷兰语",
"coord" : [
{
"x" : 75,
"y" : 46
},
{
"x" : 140,
"y" : 46
},
{
"x" : 140,
"y" : 72
},
{
"x" : 75,
"y" : 72
}
],
"exception" : 0,
"words" : [
{
"conf" : "1.0",
"content" : "荷兰语",
"coord" : [
{
"x" : 75,
"y" : 46
},
{
"x" : 139,
"y" : 46
},
{
"x" : 139,
"y" : 73
},
{
"x" : 75,
"y" : 73
}
]
}
]
},
{
"angle" : 0.5509040355682373,
"conf" : 0.9999803900718689,
"content" : "Hallo, hoe is het weer",
"coord" : [
{
"x" : 44,
"y" : 120
},
{
"x" : 328,
"y" : 117
},
{
"x" : 328,
"y" : 150
},
{
"x" : 44,
"y" : 153
}
],
"exception" : 0,
"words" : [
{
"conf" : "1.0",
"content" : "Hallo,",
"coord" : [
{
"x" : 43,
"y" : 120
},
{
"x" : 114,
"y" : 119
},
{
"x" : 115,
"y" : 153
},
{
"x" : 44,
"y" : 153
}
]
},
{
"conf" : "1.0",
"content" : "hoe",
"coord" : [
{
"x" : 129,
"y" : 119
},
{
"x" : 164,
"y" : 118
},
{
"x" : 165,
"y" : 152
},
{
"x" : 130,
"y" : 152
}
]
},
{
"conf" : "1.0",
"content" : "is",
"coord" : [
{
"x" : 183,
"y" : 118
},
{
"x" : 196,
"y" : 118
},
{
"x" : 197,
"y" : 152
},
{
"x" : 184,
"y" : 152
}
]
},
{
"conf" : "1.0",
"content" : "het",
"coord" : [
{
"x" : 210,
"y" : 118
},
{
"x" : 245,
"y" : 118
},
{
"x" : 246,
"y" : 151
},
{
"x" : 211,
"y" : 152
}
]
},
{
"conf" : "1.0",
"content" : "weer",
"coord" : [
{
"x" : 260,
"y" : 117
},
{
"x" : 326,
"y" : 117
},
{
"x" : 327,
"y" : 151
},
{
"x" : 261,
"y" : 151
}
]
}
]
},
{
"angle" : 356.71075439453125,
"conf" : 0.99095529317855835,
"content" : "vandaag",
"coord" : [
{
"x" : 44,
"y" : 154
},
{
"x" : 158,
"y" : 160
},
{
"x" : 156,
"y" : 192
},
{
"x" : 42,
"y" : 186
}
],
"exception" : 0,
"words" : [
{
"conf" : "1.0",
"content" : "vandaag",
"coord" : [
{
"x" : 43,
"y" : 153
},
{
"x" : 156,
"y" : 160
},
{
"x" : 154,
"y" : 193
},
{
"x" : 41,
"y" : 186
}
]
}
]
}
],
"width" : 491
}
],
"protoc" : "2.0",
"version" : "4.5.0.1120"
}
参数名 | 类型 | 描述 |
---|---|---|
version | string | 引擎版本号 |
category | string | 引擎调用模式 |
protocol | string | 输出协议版本号,当前协议版本号为2.0 |
pages | array | 页面集合 |
pages.height | int | 页面的高度,以像素为单位 |
pages.width | int | 页面的宽度,以像素为单位 |
pages.exception | int | 异常信息,0(正常)、-1(异常) |
pages.angle | float | 旋转角度,范围[0,360],顺时针方向 |
pages.lines | array | 文本行,若未检测到,则该字段不存在 |
pages.tables | array | 表格,若未检测到,则该字段不存在 |
pages.checkboxes | array | 复选框,若未检测到,则该字段不存在 |
pages.seals | array | 印章,若未检测到,则该字段不存在 |
pages.fingerprints | array | 指印区,若未检测到,则该字段不存在 |
pages.graphs | array | 插图,若未检测到,则该字段不存在 |
pages.headers | array | 页眉,若未检测到,则该字段不存在 |
pages.footers | array | 页脚,若未检测,则该字段不存在 |
pages.blocks | array | 段落,若未检测到文本行或未开启分块功能,则该字段不存在。在简历、合同 文档结构化中默认按照blocks的结构进行输出 |
pages.page_numbers | array | 页码,若未检测到,则该字段不存在 |
pages.expressions | array | 公式,若未检测到,则该字段不存在 |
pages.barcodes | array | 条码,若未检测到,则该字段不存在 |
参数名 | 类型 | 描述 |
---|---|---|
id | int | 文本行编号,取值范围大于等于0的整数 |
coord | array | 位置坐标,至少4个点 |
coord.x | int | 坐标轴x |
coord.y | int | 坐标轴y |
angle | float | 文本行角度,取值范围[0-360]度 |
conf | float | 置信度,取值范围[0-1] |
type | string | 文本行数据类型(handwriting手写、print印刷) |
exception | int | 异常信息(0:正常,-1:异常返回) |
content | string | 识别结果 |
words | array | 单词集合 |
words.content | string | 识别结果 |
words.conf | float | 置信度,取值范围[0-1] |
words.coord | array | 位置坐标,至少4点 |
words.coord.x | int | 坐标轴x |
words.coord.y | int | 坐标轴y |
word_units | array | 单字集合(中文单字,英文单个字母) |
word_units.content | string | 识别结果 |
word_units.conf | float | 置信度,取值范围[0-1] |
word_units.coord | array | 位置坐标,至少4点 |
word_units.coord.x | int | 坐标轴x |
word_units.coord.y | int | 坐标轴y |
参数名 | 类型 | 描述 |
---|---|---|
id | int | 表格编号,若id相同则说明同属于一个表格 |
coord | array | 位置坐标,至少4点 |
coord.x | int | 坐标轴x |
coord.y | int | 坐标轴y |
cols | int | 表格划分出的列数 |
rows | int | 表格划分出的行数 |
height_set | array | 表格单元格高度的集合,以像素为单位 |
width_set | array | 表格单元格宽度的集合,以像素为单位 |
cells | array | 单元格的集合 |
cells.coord | array | 位置坐标,至少四点 |
cells.coord.x | int | 坐标轴x |
cells.coord.y | int | 坐标轴y |
cells.col | int | 单元格的列号 |
cells.row | int | 单元格的行号 |
cells.colspan | int | 单元格横跨的列数 |
cells.rowspan | int | 单元格横跨的行数 |
cells.lines | array | 协议2.0不推荐使用 |
cells.elements | array | 单元格中插入要素的集合 |
cells.elements.id | int | 单元格中插入要素的编号 |
cells.elements.type | string | 单元格中插入其他要素的类型(table表格、graph插图、checkbox复选框、seal印章、fingerprint指印、block段落) |
参数名 | 类型 | 描述 |
---|---|---|
id | int | 复选框编号 |
coord | object | 位置坐标,至少4点 |
coord.x | int | 坐标轴x |
coord.y | int | 坐标轴x |
type | string | tick: 勾选(涂黑)框 cross: 叉选框 blank: 空白框 |
参数名 | 类型 | 描述 |
---|---|---|
id | int | 印章编号 |
coord | array | 目标区域位置信息,至少4点 |
coord.x | int | 坐标轴x |
coord.y | int | 坐标轴y |
elements | array | 印章中插入要素的集合 |
elements.id | int | 印章中插入要素的编号 |
elements.type | string | 印章中插入要素的类型,table(表格)、graph( 插图)、 checkbox(复选框)、seal(印章)、fingerprint(指印)、 block(段落) |
参数名 | 类型 | 描述 |
---|---|---|
id | int | 指印编号 |
coord | object | 位置坐标,至少4点 |
coord.x | int | 坐标轴x |
coord.y | int | 坐标轴y |