Python3 Ocr 初探

 2023-09-09 阅读 24 评论 0

摘要:环境概述 |Python|3.9.2 | |-pytesseract 客户端-|-5.0-| | pytesseract 依赖库| 0.3.8 | | 语言包|chi_sim.traineddata、chi_sim_vert.traineddata | 下载地址 CSDN资源地址:https://download.csdn.net/download/yanxilou/76285648 客户端:https://github.com

环境概述

|Python|3.9.2 |
|-pytesseract 客户端-|-5.0-|
| pytesseract 依赖库| 0.3.8 |
| 语言包|chi_sim.traineddata、chi_sim_vert.traineddata |

下载地址

CSDN资源地址:https://download.csdn.net/download/yanxilou/76285648
客户端:https://github.com/UB-Mannheim/tesseract/wiki
在这里插入图片描述
语言包:https://github.com/tesseract-ocr/tessdata

在这里插入图片描述依赖库: pip install pytesseract

在这里插入图片描述

修改配置

opencv ocr。语言包放到这里:
在这里插入图片描述修改cmd路径:
在这里插入图片描述在这里插入图片描述

目录结构

在这里插入图片描述

代码

from PIL import Image
import pytesseractdef read_text(text_path):# 打开图片im = Image.open(text_path)# 转化为8bit的黑白图片imgry = im.convert('L')# 二值化,采用阈值分割算法,threshold为分割点threshold = 140table = []for j in range(256):if j < threshold:table.append(0)else:table.append(1)out = imgry.point(table, '1')# 识别文本text = pytesseract.image_to_string(out, lang="chi_sim", config='--psm 6')return text
if __name__ == '__main__':print(read_text(r'.\img\demo.png'))

效果

在这里插入图片描述

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/4/29367.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息