pipreqs
pipreqs可以帮你找到当前项目的所有组件及其版本。就是当别人给你一个程序的时候,你要在自己电脑上运行起来,就需要安装程序所依赖的组件,总不能自己一个一个找吧。
使用步骤
- 在项目根目录下执行命令
- pipreqs ./ # 报错就执行下面这条
- pipreqs ./ –encoding=utf-8
- 可以在
./
路径下看到生成了requirements.txt文件 - 执行下面代码就会把项目用到的所有模块安装在虚拟环境中
- pip3 install -r requirements.txt
pytesseract
介绍
OCR技术是光学字符识别的缩写(Optical Character Recognition),是通过扫描等光学输入方式将各种票据、报刊、书籍、文稿及其它印刷品的文字转化为图像信息,再利用文字识别技术将图像信息转化为可以使用的计算机输入技术。可应用于银行票据、大量文字资料、档案卷宗、文案的录入和处理领域。
环境
采用ubuntu。
安装
安装 tesseract-ocr 包
sudo apt-get install tesseract-ocr
安装pytesseract和PIL库
pytesseract
pip install pytesseract
PIL
pip install pillow
图片识别使用
非中文图片识别
import pytesseract
from PIL import Image
def read_text(image_path):
image = Image.open(image_path)
text = pytesseract.image_to_string(image=image)
print(text)
if __name__ == '__main__':
image_path = 'ddd.jpg'
read_text(image_path)
中文图片识别
要想识别的中文需要添加中文字库,需要在ubuntu 系统中 找到 tessdata 文件夹把中文字库放进去,也可以在线安装中文字库:
sudo apt-get install tesseract-ocr-chi-sim
代码:
# pip show pytesseract
import pytesseract
from PIL import Image
def read_text(image_path):
image = Image.open(image_path)
text = pytesseract.image_to_string(image=image,lang='chi_sim')
print(text)
if __name__ == '__main__':
image_path = 'dddeee.jpg'
read_text(image_path)
命令行识别
# 识别英文:
tesseract e.png 1 #1 是存储获取内容的文件,会在本地生成一个1文件
# 识别中文
tesseract --help # 查看帮助
tesseract --list -langs # 查看是否安装了中文库chi_sim
tesseract -l chi_sim c.png 1 # 1也是结果的文件把识别的结果存到此文件中
Tesseract
如果你是在windows下开发的话,可能要用到如下的某个安装包: