Ubuntu系统 OCR文字识别与 Latex公式识别

一、OCR文字识别

Step1:安装tesseract

tesseract 是一个开源的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 

Step2:安装中文包

中文包下载路径, 下载完成并解压后,将解压文件中的*.traineddata 相关文件拷贝到 usr/share/tesseract-ocr/4.00/tessdata/ 路径下,然后继续安装;

Step3:安装截图等功能包

sudo apt-get install gnome-screenshot
sudo apt-get install xclip
sudo apt-get install imagemagick

Step4:制作shell文件

在Step2 中有一个 OCR.txt 文件,拷贝为 ocr.sh文件,如下所示:

#!/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

exit

![在这里插入图片描述](https://img-blog.csdnimg.cn/7b98acdb488e4199a71a722966e3572a.png
注意
1. 将文件中SCR="路径那里替换成你想要存放截图以及识别结果txt文档的路径
2. 因中文识别后文字与文字间常出现不必要的空格,可以将上图蓝框位置改成cat $SCR.txt| tr -d ' '| tr -d '\n' | xclip -selection clipboard ,表示去除识别出的文本间的空格、换行 (蓝框注释的表示只去除识别出的文本间的空格),按需选用。

Step5:设置快捷键

在 设置 → \rightarrow 键盘中添加自定义快捷键,如下所示,设置完成后按Alt + q即可直接截图识别并已复制到粘贴板
![在这里插入图片描述](https://img-blog.csdnimg.cn/8c9de58ce87247d2afa14324cc5b4950.png

二、Latex公式识别

方案一:官网直接下载linux版本

官网直接下载linux版本,然后找到该文件,右键属性,勾选允许作为执行程序。官网链接
在这里插入图片描述

方案二:snap安装

cd ~/Downloads
wget https://download.mathpix.com/linux/Mathpix_Snipping_Tool-x86_64.v03.00.0050.AppImage -O Mathpix_Snipping_Tool.AppImage
chmod 777 ./Mathpix_Snipping_Tool.AppImage
./Mathpix_Snipping_Tool.AppImage
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值