- 前言
- Step1:安装tesseract
- Step2: 制作Shell文件
- Step3:设置快捷键,一键调用shell脚本
- 下面是Latex公式识别
现在的工作重心慢慢往ubuntu上靠拢,所以在闲暇之余摸索一下ubuntu的小功能。如果在ubuntu上码字的话,尤其是写技术文档,OCR识别和公式识别应该会经常用到。自己也是折腾了好长时间,终于搞定了,分享记录一下过程。以下,enjoy!
Step1:安装tesseracttesseract是一个开源的OCR引擎,最初是由惠普公司开发用来作为其平板扫描仪的OCR引擎,2005年惠普将其开源出来,之后google接手负责维护。目前稳定的版本是3.0。4.0版本加入了基于LSTM的神经网络技术,中文字符识别准确率有所提高。
sudo add-apt-repository ppa:alex-p/tesseract-ocr sudo apt-get update sudo apt-get install tesseract-ocr
然后安装一下中文库。国内可以从下面的链接下载(仅有简体中英文字库):
https://share.weiyun.com/5IJtlcY(感谢作者,好人一生平安)
下载完成之后把.traineddata字库文件放到tessdata目录下,默认路径usr/share/tesseract-ocr/4.00/tessdata
然后继续安装
sudo apt-get install gnome-screenshot sudo apt-get install xclip sudo apt-get install imagemagickStep2: 制作Shell文件
将以下代码复制到文档,并将后缀改成.sh 并增加运行权限 sudo chmod a+x *.sh
注意:"SCR="路径那里替换成你想要存放截图以及识别结果txt文档的路径
#!/bin/env bash # Dependencies: tesseract-ocr imagemagick gnome-screenshot xclip #Name: OCR Picture #Author:andrew #Fuction: take a screenshot and OCR the letters in the picture #Path: /home/Username/... #Date: 2020-02-10 #you can only scan one character at a time SCR= "/home/Username/documents/temp" ####take a shot what you wana to OCR to text gnome-screenshot -a -f $SCR.png ####increase the png mogrify -modulate 100,0 -resize 400% $SCR.png #should increase detection rate ####OCR by tesseract tesseract $SCR.png $SCR &> /dev/null -l eng+chi1 ####get the text and copy to clipboard cat $SCR.txt | xclip -selection clipboard exitStep3:设置快捷键,一键调用shell脚本
进入:设置→键盘 拉到底部,点击+
名称:自由设置,建议以shell脚本名称命名
命令:bash 这里换成你自己shell脚本所在的路径/OCR.sh
注意bash后面有一个空格
配置完成后直接按F4即可直接截图识别啦
提到公式识别,Mathpix Snip在科研圈中应该是人尽皆知,只需要截个图,Mathpix Snip就可以将截图中的公式自动转化为 LaTex 代码表达式,而且准确度出奇的高。刚开始这软件是免费的,后面收费了,不过每个账号每个月有30次的免费次数,所以不限麻烦的话多注册几个账号也能用,另外Mathpix也可以识别中文。
可以官网直接下载linux版本
/添https://mathpix.com
然后找到该文件,右键属性,勾选允许作为执行程序
然后打开就可以用拉。
ctrl+alt+m直接截图识别,超级方便。
也可以通过snap安装
cd ~/Downloads wget https://download.mathpix.com/linux/Mathpix_Snipping_Tool-x86_64.v03.00.0050.AppImage -O Mathpix_Snipping_Tool.AppImage (Note: The link might change, check it on https://mathpix.com/) chmod 777 ./Mathpix_Snipping_Tool.AppImage ./Mathpix_Snipping_Tool.AppImage



