图片中识别出中文开源OCR使用

从一张图片中识别出中文,通过python来实现,这种这么高大上的黑科技我们普通人自然搞不了,去github找了一个似乎能满足需求的开源库-tesseract-ocr:

You may encounter build failures or other breakages.
Please create pull-requests instead of filing issues.
==> Installing dependencies for tesseract: libpng, libtiff, leptonica
==> Installing tesseract dependency: libpng
==> Downloading https://homebrew.bintray.com/bottles/libpng-1.6.24.el_capitan.bo

################################################################## 100.0%

==> Pouring libpng-1.6.24.el_capitan.bottle.tar.gz
�� /usr/local/Cellar/libpng/1.6.24: 26 files, 1.2M
==> Installing tesseract dependency: libtiff
==> Downloading https://homebrew.bintray.com/bottles/libtiff-4.0.6_2.el_capitan.

################################################################## 100.0%

==> Pouring libtiff-4.0.6_2.el_capitan.bottle.tar.gz
�� /usr/local/Cellar/libtiff/4.0.6_2: 261 files, 3.4M
==> Installing tesseract dependency: leptonica
==> Downloading https://homebrew.bintray.com/bottles/leptonica-1.73.el_capitan.b

################################################################## 100.0%

==> Pouring leptonica-1.73.el_capitan.bottle.tar.gz
�� /usr/local/Cellar/leptonica/1.73: 50 files, 5.4M
==> Installing tesseract
==> Downloading https://homebrew.bintray.com/bottles/tesseract-3.04.01_2.el_capi

################################################################## 100.0%

==> Pouring tesseract-3.04.01_2.el_capitan.bottle.tar.gz
�� /usr/local/Cellar/tesseract/3.04.01_2: 76 files, 39M

在Mac上真的很快,就弄好了
笔者的开发环境如下:

macosx
python 3.6
brew
安装tesseract

brew install tesseract
1
安装python对应的包:pytesseract

pip install pytesseract 记得sudo避免权限问题

怎么用?

如果要识别中文需要下载对应的训练集:https://github.com/tesseract-ocr/tessdata
,下载”chi_sim.traineddata”,50.2 MB 然后copy到训练数据集的存放路径,如:

/tessearact/3.0xxx/share/

执行的代码:

!/usr/bin/env python3

-- coding: utf-8 --

import pytesseract
from PIL import Image

open image

image = Image.open(‘test.png’)
code = pytesseract.image_to_string(image, lang=’chi_sim’)
print(code)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值