当前位置: 首页 > news >正文

python pytesseract 中文文字批量识别

用pytesseract 来批量把图片转成文字
1、安装好 pytesseract 包
 
2、下载安装OCR

https://download.csdn.net/download/m0_37622302/88348824icon-default.png?t=N7T8https://download.csdn.net/download/m0_37622302/88348824

Index of /tesseracticon-default.png?t=N7T8https://digi.bib.uni-mannheim.de/tesseract/

我是win10 64位,所以下载了 tesseract-ocr-w64-setup-v5.3.0.20221214.exe

安装软件目录在D:\Program Files\ocr\

下载 chi_sim.traineddata

放在 D:\Program Files\ocr\tessdata

3、编辑环境变量

TESSDATA_PREFIX

D:\Program Files\ocr\tessdata

4、测试环境一切就绪

tesseract -v 测 试一下,成功

5、pytesseract 编码
import os
import pytesseract
from PIL import Imagedef jpg_to_text(input_folder, output_folder):# 遍历输入文件夹中的所有JPG图片for filename in os.listdir(input_folder):if filename.endswith(".png"):# 构造输入和输出文件的路径input_path = os.path.join(input_folder, filename)output_path = os.path.join(output_folder, f"{filename}.txt")# 打开图片文件并进行文字识别image = Image.open(input_path)text = pytesseract.image_to_string(image, 'chi_sim')# 将识别结果写入输出文件with open(output_path, "w") as file:file.write(text)if __name__ == '__main__':jpg_to_text("F:/table/cc", "F:/table/aa")

识别中文一定需要这个参数,不然会出现乱码

最后就可以见证奇迹了

http://www.lryc.cn/news/168692.html

相关文章:

  • Python 之plt.plot()的介绍以及使用
  • 自动化生成代码:MyBatis 的 Generator与MyBatis-Plus 的 AutoGenerator
  • 达梦数据库-DW-国产化--九五小庞
  • LeetCode 753. 破解保险箱【欧拉回路,DFS】困难
  • 深度学习概念(术语):Fine-tuning、Knowledge Distillation, etc
  • tcp_v4_connect函数的解析
  • go-channel
  • K8s操作命令
  • 【MySQL】 MySQL数据库基础
  • vscode 下载安装
  • springboot对接postgres
  • [python 刷题] 242 Valid Anagram
  • 算法通过村第七关-树(递归/二叉树遍历)青铜笔记|手撕递归
  • #循循渐进学51单片机#点亮你的LED#not.2
  • 基于Java+SpringBoot+Vue+uniapp点餐小程序(亮点:协同过滤算法、会员系统,购物车结算、在线聊天)
  • 深度学习-全连接神经网络-详解梯度下降从BGD到ADAM - [北邮鲁鹏]
  • 数据结构--二叉排序树
  • Python | 根据子列表中的第二个元素对列表进行排序
  • qsort函数详细讲解以及利用冒泡排序模拟实现qsort函数
  • C++QT day6
  • List与ArrayList
  • 【C++】特殊类的设计
  • 机器学习:PCA(Principal Component Analysis主成分)降维
  • linux服务器slab缓存回收方案设计
  • Apache Spark 的基本概念
  • 通讯协议介绍CoAP 协议解析
  • React 开发一个移动端项目(2)
  • 51单片机 点阵矩阵 坤坤代码
  • Android13-图片视频选择器
  • 【问题处理】GIT合并解决冲突后,导致其他人代码遗失的排查