200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > 利用Mathpic OCR和Quicker实现数学公式的快速识别

利用Mathpic OCR和Quicker实现数学公式的快速识别

时间:2020-07-06 01:49:53

相关推荐

利用Mathpic OCR和Quicker实现数学公式的快速识别

利用Mathpic OCR和Quicker实现数学公式的快速识别

写在前面

相信很多小伙伴已经习惯了使用Mathpic来识别手写的或者论文中的数学公式,但是现在Mathpic每个月只能免费查询50次,如果想继续查询需要5美刀包月,这价格优点扛不住啊!不过, Mathpix官网还算是优点良心,给开发者留了条后门,使用API查询每月可免费查询1,000条,相信对于一般的小伙伴来说已经是绰绰有余了~

具体收费标准如下:

First 1000:requests free1-100K requests:$0.004/request100-300K requests:$0.002/request300K+ requests:$0.001/request

账号的申请过程,如下面网址所示

Mathpix收费了?快使用API吧,一个月免费识别1000次!

不过申请过程中,需要???绑定信用卡???,有忌讳的小伙伴就只能另外想别的方法了~

关于信用卡,这里讲一下,我用的不是visa信用卡,额度也是非常低,不过也还是能通过验证

当然,配合上Quicker软件可以大大提高效率。就像下面这样

????????????????

准备过程

所需环境

Python3.X 需要安装第三方requests模块以及pillow模块

Win10 Win7应该也是可以滴

Quicker 有免费版,当然也有收费版,一个月也就一瓶饮料钱

配置过程

下面是我自己的配置过程,大家也可以使用自己所需的方式进行配置

PC端
将如下的simple.py置于C:\CustomStartUp\formrec文件夹内(或其他的文件夹下,路径中不要带空格及中文!!!),py文件中在APP_IDAPP_KEY中填写自己申请账号过程中官网给出使用API的app id和app key创建一个latexform_start.txt文件,置于C:\CustomStartUp文件夹下,内部填写simple.py文件的绝对路径地址(包含simple.py),比如我的地址是C:\CustomStartUp\formrec\simple.py

# simple.pyimport osimport base64import requestsimport jsonfrom PIL import ImageGrab# APP_ID=my-id APP_KEY=my-key python3 simple.py # Fill in your app id.APP_ID = 'your APP_ID'# Fill in your app key.APP_KEY = 'your APP_KEY'## Common module for calling Mathpix OCR service from Python.## N.B.: Set your credentials in environment variables APP_ID and APP_KEY,# either once via setenv or on the command line as in#env = os.environdefault_headers = {'app_id': env.get('APP_ID', APP_ID),'app_key': env.get('APP_KEY', APP_KEY),'Content-type': 'application/json'}service = '/v3/latex'## Return the base64 encoding of an image with the given filename.#def image_uri(filename):image_data = open(filename, "rb").read()return "data:image/jpg;base64," + base64.b64encode(image_data).decode()## Call the Mathpix service with the given arguments, headers, and timeout.#def latex(args, headers=default_headers, timeout=30):r = requests.post(service,data=json.dumps(args), headers=headers, timeout=timeout)return json.loads(r.text)def mathpix_clipboard(): # Identify the clipboard formulaim = ImageGrab.grabclipboard()fp = os.path.abspath(__file__)fp = os.path.dirname(fp) # Get the file dir. fn = os.path.join(fp, 'equa.png') # Get the filename where the picture is stored.im.save(fn,'PNG')r = latex({'src': image_uri(fn),'formats': ['latex_simplified']})print(r['latex_simplified'])if __name__ == '__main__':mathpix_clipboard()

Quicker配置
在需要运行的软件上添加组合动作(我平常用Typora和为知云上做笔记,所以在这两个上面添加了)

1、读取文件 2、运行脚本 3、组合成文本 4、发送文本到窗口

编辑完成以后如下

使用过程

使用Snipaste或者其他截图软件将需要转换的图片截取到剪切板中打开相应的Markdown或者Latex软件(已经在Quicker上设置过的软件)点击公式识别按钮,即可在相应软件上生成对应的Latex代码

Now, everything is ready, have fun~

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。