美文网首页
tesseract文字识别

tesseract文字识别

作者: 升不上三段的大鱼 | 来源:发表于2020-04-02 22:35 被阅读0次

尝试利用tesseract做一下文字识别,据说效果一般,试了一下真的效果一般。

  1. 相关安装和设置
    https://blog.csdn.net/m0_37215794/article/details/81944027
  2. 安装遇到的问题
    系统找不到指定文件: 在代码前加两行
import pytesseract
from PIL import Image

# 这里是自己的安装路径
pytesseract.pytesseract.tesseract_cmd = 'D:/Program Files/Tesseract-OCR/tesseract.exe'
tessdata_dir_config = '--tessdata-dir "D:/Program Files/Tesseract-OCR/tessdata"'

image = Image.open("text.png")
text = pytesseract.image_to_string(image, lang='chi_sim',,config=tessdata_dir_config)
print(text)

结果长这样:


仿佛在看盗文,连蒙带猜都不知道啥意思。

如果有报错:
pytesseract.pytesseract.TesseractError: (3221225477, '')
这是tesseract崩了,也没什么解决办法。

actual_tessdata_num_entries_ <= TESSDATA_NUM_ENTRIES:Error:Assert failed:in file ....\ccutil\tessdatamanager.cp p, line 50
下载的语言包与版本不匹配,可以在命令行里用输入 tesseract -v,查看自己的版本,然后下载对应版本的语言包

Too many unichars in ambiguity on line xxxxxxxx
意思是有字长得差不多,有歧义,所以提示一下(中文里长得像的字太多了==)。

  1. 在命令行运行
# tesseract 图片 输出文件 [-l 语言选项] [-psm pagesegmode] [configfile...]
tesseract img.jpg out -l chi_sim

相关文章

网友评论

      本文标题:tesseract文字识别

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