美文网首页
2、how to extract text from image

2、how to extract text from image

作者: BigBigGuy | 来源:发表于2019-01-11 20:38 被阅读0次

Using tesseract with Python(Tesseract OCR with Python)

1、安装OCR库

sudo apt-get install tesseract-ocr

2、命令行测试

tesseract test.png output.txt

3、安装Python库(PIL分支Pillow和ORC的python库)

sudo pip3 install Pillow pytesseract

4、一段超简单的代码(默认识别英文)

from PIL import Image
import pytesseract

im = Image.open("test.png")
text = pytesseract.image_to_string(im)
print(text)

5、中文识别,结果较差

首先要下载tesseract的中文包:chi_sim.traineddata
https://github.com/tesseract-ocr/tessdata/blob/master/chi_sim.traineddata

然后拷贝到tessdata文件夹

sudo mv chi_sim.traineddata /usr/share/tesseract-ocr/4.00/tessdata

再将上面代码改一改

text = pytesseract.image_to_string(image= im, lang="chi_sim")

相关文章

网友评论

      本文标题:2、how to extract text from image

      本文链接:https://www.haomeiwen.com/subject/yprfdqtx.html