数学公式图片OCR API

小艾同学 ... 大约 2 分钟

# 数学公式图片OCR API

# 简介

用户需要先注册登录,然后才能正常使用。注意使用的时候需要带 token。

# 示例图片

Image 1
Image 1
Image 1
Image 1
Image 1
Image 1
Image 1
Image 1
Image 1
Image 1
Image 1

# error 出错公式

Image 1
Image 1

# 接口/路由/入口

  • 接口名称:数学公式图片OCR
  • 接口地址:https://www.docpartner-serve.com/python/bpInterfaceLatexOcrOnly
  • 请求方式:POST
  • 响应类型:JSON(同步)
  • content-type:application/json

# 输入说明

{
    "requestData": {
        "reqImgData": "asdfasf", // base64 图片base64 数据 不需要 data 开头 
    }
}
1
2
3
4
5

# 输出说明

{
    "isSuccessful": True,
    "errorMsg" : "",
    "data" : {
        "respData":{
            "latex":str
            "scores":float
        }
    }
}
1
2
3
4
5
6
7
8
9
10

# 程序示例

# js 示例

// 基于 axios

import axios from "axios"

let token = "TODO" // TODO 

let bpInterfaceLatexOcrOnly = "/bpInterfaceLatexOcrOnly"

let requestJsonData = {
    requestData: {
        reqImgData: "TODO", // base64 字符串
    }
}

axios.post(
    bpInterfaceLatexOcrOnly, 
    requestJsonData,
    {
        baseURL: 'https://www.docpartner-serve.com/python/', // TODO 
        headers: {
            "Authorization":`Bearer ${token}`,
            "Content-Type":"application/json;charset=utf-8",
            
        },
        responseType: 'json'
    }
)
.then(resp => {
    if (resp.data.isSuccessful) {
        console.log(resp.data.data)
    } else {
        console.log(`请求api失败!${resp.data.errorMsg}`);
    }
})
.catch(err => {
    console.log(err)
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

# python 示例

# 基于 requests - 已测试

import os 
import base64
import requests

token = "" # TODO


bp = "bpInterfaceLatexOcrOnly"

url = "https://www.docpartner-serve.com/python/{bp}".format(
    bp=bp
) # 接口地址


imgPath = "test.png" # TODO 
with open(imgPath, "rb") as f:
    imgDataStr = base64.b64encode(f.read()) # --> b''
imgDataBase64 = imgDataStr.decode() # --> str  图片 base64 编码成字符串

jsondata = {
    "requestData": {
        "reqImgData": imgDataBase64,
    }
}
headers = {
    'Authorization': "Bearer " + token
}
r = requests.post(url,headers=headers,data=None,json=jsondata)

assert type(r.json()) == dict
print(type(r.json()))
print(r.json())

# {'data': {'respData': {'latex': '\\left\\{ \\begin{array} { l } { a ^ { 2 } - 1 \\not = 0 } \\\\ { \\Delta = 4 ( a + 1 ) ^ { 2 } - 4 ( a ^ { 2 } - 1 ) \\geqslant 0 } \\\\ { x _ { 1 } + x _ { 2 } = \\frac { 2 } { a - 1 } } \\\\ { x _ { 1 } x _ { 2 } = \\frac { 1 } { a ^ { 2 } - 1 } } \\\\ \\end{array} \\right. ,', 'scores': 0.6}}, 'errorMsg': '', 'isSuccessful': True}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
上次编辑于: 2025年5月27日 00:37