Open Qingquan-Li opened 6 years ago
需求:从一张图片中识别出中文 实现:使用 Python 并借助开源库 Tesseract 实现
Tesseract是一种开源的光学字符识别(OCR)引擎,可根据Apache 2.0许可证使用。它可以直接使用,或(对于程序员)使用API从图像中提取类型,手写或打印的文本。它支持各种语言。 参考: https://github.com/tesseract-ocr/tesseract/wiki https://en.wikipedia.org/wiki/Tesseract_(software)
开发环境:
brew install tesseract
pip3 install pytesseract
tesseract 支持多种语言:https://github.com/tesseract-ocr/tesseract/blob/master/doc/tesseract.1.asc#languages
从 https://github.com/tesseract-ocr/tessdata 下载简体中文数据集 chi_sim.traineddata 到 /usr/local/Cellar/tesseract/3.05.01/share/tessdata 目录下:
#!/usr/bin/env python3 # -*- coding: utf-8 -*- try: import Image except ImportError: from PIL import Image import pytesseract # open image image = Image.open('/Users/fatli/Desktop/dufu.png') code = pytesseract.image_to_string(image, lang='chi_sim') print(code)
附:英文识别
需求:从一张图片中识别出中文 实现:使用 Python 并借助开源库 Tesseract 实现
开发环境:
一、安装 tesseract
二、安装 Python 对应的包
三、下载对应的中文训练数据
tesseract 支持多种语言:https://github.com/tesseract-ocr/tesseract/blob/master/doc/tesseract.1.asc#languages
从 https://github.com/tesseract-ocr/tessdata 下载简体中文数据集 chi_sim.traineddata 到 /usr/local/Cellar/tesseract/3.05.01/share/tessdata 目录下:
四、Show the code
附:英文识别