Python 安装使用 tesseract OCR 识别中文

前言:

i、中文识别效果更好的开源OCR库:CnOCR 使用教程

ii、6款开源中文OCR使用介绍(亲测效果):点我查看

iii、windows安装 tesserract教程:

windows安装:点我查看教程1点我查看教程2

windows安装完成,设置好环境变量后,报找不到路径的错误点这里:解决办法

本文为 CentOS 下安装教程

Tesseract的OCR引擎目前已作为开源项目发布在Google Project,其项目主页在这里查看 https://github.com/tesseract-ocr, 
它支持中文OCR,并提供了一个命令行工具。python中对应的包是pytesseract. 通过这个工具我们可以识别图片上的文字。

1、安装tesseract

yum install tesseract

2、安装pytesseract

pip install pytesseract

3、下载对应的中文训练集:https://github.com/tesseract-ocr/tessdata,下载”chi_sim.traineddata”,然后copy到训练数据集的存放路径。我安装后拷贝的路径是:

/usr/share/tesseract/tessdata

4、使用python调用识别中文

import pytesseract
from PIL import Image

image = Image.open('data/ocr.png')
print pytesseract.image_to_string(image, lang = 'chi_sim')

5、图片识别准确率不高问题

from PIL import Image, ImageEnhance


image = Image.open('data/tesseract.png')
enhancer = ImageEnhance.Contrast(image)
image = enhancer.enhance(4)
import platform
import pytesseract
from PIL import Image, ImageEnhance


image = Image.open('data/tesseract.png')
enhancer = ImageEnhance.Contrast(image)
image = enhancer.enhance(4)

if platform.system() == 'Windows':
    pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files (x86)\Tesseract-OCR\tesseract"
    tessdata_dir_config = '--tessdata-dir "C:\\Program Files (x86)\\Tesseract-OCR\\tessdata"'
    print pytesseract.image_to_string(image, lang = 'chi_sim', config = tessdata_dir_config)
else:
    print pytesseract.image_to_string(image, lang = 'chi_sim')

如果需要使用更高精度的可以尝试百度的API:文字识别-百度智能云

参考:wxPython利用pytesser模块实现图片文字识别_v2psv的博客-优快云博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值