百度智能云教育场景文字识别API文档 - 公式识别
文档简介:
接口描述:
支持对试卷中的数学公式及题目内容进行识别,可提取公式部分进行单独识别,也可对题目和公式进行混合识别,并返回Latex格式公式内容及位置信息,便于进行后续处理。
【百度智能云】通用场景文字识别
【百度智能云】卡证文字识别
【百度智能云】财务票据文字识别
【百度智能云】医疗票据文字识别
【百度智能云】交通场景文字识别
【百度智能云】其他场景文字识别
【百度智能云】iOCR自定义模板文字识别
【百度智能云】通用文字识别(标准版)
【百度智能云】通用文字识别(高精度版)
【百度智能云】网络图片文字识别
【百度智能云】手写文字识别
【百度智能云】门脸文字识别
【百度智能云】防疫场景文字识别
该接口的公有云服务即将下线,若您仍需要使用公式识别,您可以选择试卷分析与识别。 试卷分析与识别也可支持公式识别,同时提供版面分析功能,可分版块输出OCR识别结果。
接口描述
支持对试卷中的数学公式及题目内容进行识别,可提取公式部分进行单独识别,也可对题目和公式进行混合识别,并返回Latex格式公式内容及位置信息,便于进行后续处理。
在线调试
您可以在 示例代码中心 中调试该接口,可进行签名验证、查看在线调用的请求内容和返回结果、示例代码的自动生成。
请求说明
请求示例
HTTP 方法:POST
请求URL: https://aip.baidubce.com/rest/2.0/ocr/v1/formula
URL参数:
参数 | 值 |
---|---|
access_token | 通过API Key和Secret Key获取的access_token,参考“Access Token获取” |
Header如下:
参数 | 值 |
---|---|
Content-Type | application/x-www-form-urlencoded |
Body中放置请求参数,参数详情如下:
请求参数
参数 | 是否必选 | 类型 | 可选值范围 | 说明 |
---|---|---|---|---|
image | 和url二选一 | string | - |
图像数据,base64编码后进行urlencode,需去掉编码头(data:image/jpeg;base64, ) 要求base64编码和urlencode后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/jpeg/png/bmp格式,当image字段存在时url字段失效 |
url | 和image二选一 | string | - |
图片完整URL,URL长度不超过1024字节,URL对应的图片base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/jpeg/png/bmp格式,当image字段存在时url字段失效 请注意关闭URL防盗链 |
recognize_granularity | 否 | string | big/small | 是否定位单字符位置,big:不定位单字符位置;small:定位单字符位置。默认值为big |
detect_direction | 否 | bool | true/false |
是否检测图像朝向,默认不检测,即:false。朝向是指输入图像是正常方向、逆时针旋转90/180/270度。可选值包括: - true:检测朝向; - false:不检测朝向。 |
disp_formula | 否 | bool | true/false | 是否分离输出公式识别结果,在words_result外单独输出公式结果,展示在“formula_result”中 |
请求代码示例
提示一:使用示例代码前,请记得替换其中的示例Token、图片地址或Base64信息。
提示二:部分语言依赖的类或库,请在代码注释中查看下载地址。
curl -i -k 'https://aip.baidubce.com/rest/2.0/ocr/v1/formula?access_token=
【调用鉴权接口获取的token】' --data 'image=【图片Base64编码,需UrlEncode】
' -H 'Content-Type:application/x-www-form-urlencoded'
返回说明
返回参数
字段 | 是否必选 | 类型 | 说明 |
---|---|---|---|
direction | 否 | int32 |
图像方向,当detect_direction=true时存在。 - - 1:未定义, - 0:正向, - 1: 逆时针90度, - 2:逆时针180度, - 3:逆时针270度 |
log_id | 是 | uint64 | 唯一的log id,用于问题定位 |
words_result_num | 是 | uint32 | 识别结果数,表示words_result的元素个数 |
formula_result | 否 | bool | 是否返回单独公式识别结果,默认false |
formula_result_num | 否 | bool | 识别结果中的公式个数,表示formula_result的元素个数 |
words_result | 是 | array[] | 识别结果数组 |
+ location | 是 | object{} | 位置数组(坐标0点为左上角) |
++ left | 是 | uint32 | 表示定位位置的长方形左上顶点的水平坐标 |
++ top | 是 | uint32 | 表示定位位置的长方形左上顶点的垂直坐标 |
++ width | 是 | uint32 | 表示定位位置的长方形的宽度 |
++ height | 是 | uint32 | 表示定位位置的长方形的高度 |
+ words | 是 | string | 识别结果字符串 |
返回示例
{ "log_id": 2671713289176456793, "direction": 0, "formula_result_num": 3,
"formula_result": [ { "location": { "width": 258, "top": 265, "left": 450,
"height": 204 }, "words": "\\left\\{ \\begin{aligned} & x = - 1 1 \\\\ & y =
2 \\\\ \\end{aligned} \\right. " }, { "location": { "width": 429, "top": 546,
"left": 310, "height": 203 }, "words": "\\left\\{ \\begin{aligned} & 3 x + 2 y
= m \\\\ & n x - y = 2 \\\\ \\end{aligned} \\right. " }, { "location": { "width":
142, "top": 613, "left": 1029, "height": 71 }, "words": "m - \\left[ 1 0 0 , - \
\infty \\right) " } ], "words_result_num": 5, "words_result": [ { "location": {
"width": 168, "top": 313, "left": 292, "height": 110 }, "words": "已知" }, { "location":
{ "width": 258, "top": 265, "left": 450, "height": 204 }, "words": "\\left\\{
\\begin{aligned} & x = - 1 1 \\\\ & y = 2 \\\\ \\end{aligned} \\right. " },
{ "location": { "width": 582, "top": 319, "left": 728, "height": 84 }, "words":
"是二元一次方程组" }, { "location": { "width": 429, "top": 546, "left": 310, "height":
203 }, "words": "\\left\\{ \\begin{aligned} & 3 x + 2 y = m \\\\ & n x - y = 2 \\\\ \
\end{aligned} \\right." }, { "location": { "width": 780, "top": 597, "left": 745, "height":
88 }, "words": "的解,则 m - \\left[ 1 0 0 , - \\infty \\right) 的值是()" } ] }