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

ubuntu OCR 脚本

1. 百度 PaddleOCR 介绍

2. 环境安装

pip install paddlepaddle -i https://pypi.tuna.tsinghua.edu.cn/simple
# 进入 https://github.com/PaddlePaddle/PaddleOCR 
# 这里有个 requirements.txt
pip install paddleocr -i https://mirror.baidu.com/pypi/simple
pip install -r requirements.txt -i https://mirror.baidu.com/pypi/simple

3. 用法: my_ocr.py 图片或文件夹

#!/bin/env python
import os
import sys
import time
import logging                    # 关闭WARNING
from tqdm.auto import trange      # 进度条
from paddleocr import PaddleOCR   # 百度识别logging.disable(logging.DEBUG)    # 关闭DEBUG日志的打印
logging.disable(logging.WARNING)  # 关闭WARNING日志的打印file = "out.txt"def ocr_imgs(img):result = ocr.ocr(img, cls=False)if len(result[0]) == 0:result = ocr.ocr(img, cls=False, det=False)with open(file, 'a') as f:f.write(f'\n{img.center(50, "-")}\n')for idx in range(len(result)):res = result[idx]for line in res:if isinstance(line, list):f.write(f'{line[-1][0]}\n')elif isinstance(line, tuple):f.write(f'{line[0]}\n')# f.flush()def check_args():if len(sys.argv) < 2:print("Usage: %s <path> or <path/file>" % sys.argv[0])exit()arg = sys.argv[1]if os.path.isfile(arg):arg = os.path.dirname(arg)single_file = Trueelif os.path.isdir(arg):single_file = Falseos.chdir(arg)os.remove(file) if os.path.exists(file) else Falsereturn single_file########################################################################
if __name__ == "__main__":print(f"[{time.strftime('%X')}] 识别开始...")start = time.time()imagelist = [os.path.basename(sys.argv[1])] if check_args() else list(filter(os.path.isfile, os.listdir()))imagelist.sort(key=str.lower)ocr = PaddleOCR(use_angle_cls=False, lang="ch")  # use_angle_cls 竖文字for i in trange(len(imagelist),leave=False):image = imagelist[i]fn, ex = os.path.splitext(image)if ex in ['.jpg', '.jpeg', '.png']:  # bmp/webp/tiff/svg/gifocr_imgs(image)end = time.time()run_time = round(end - start)print(f"[{time.strftime('%X')}] 结束耗时{run_time}秒")cmd="gedit " + file + "&"os.system(cmd)
http://www.lryc.cn/news/152876.html

相关文章:

  • Go死码消除
  • 基于改进莱维飞行和混沌映射的粒子群优化BP神经网络分类研究(Matlab代码实现)
  • 12. 自动化项目实战
  • Window11下载安装jdk8-jdk11与环境变量的配置
  • Vector Search with OpenAI Embeddings: Lucene Is All You Need
  • JS算法与树(二)
  • composer 扩展库。助手库文档
  • Web弹性布局
  • 基于深度学习的AI生成式人脸图像鉴别
  • iOS开发Swift-1-Xcode创建项目
  • AI 领域中 SLAM、Planning 和 Perception 的区别和联系
  • 【数据库】MySQL基础知识全解
  • 【golang】调度系列之goroutine
  • A 股个股资金流 API 数据接口
  • 【前端】Layui动态数据表格拖动排序
  • Linux 忘记密码解决方法
  • 【计算机组成 课程笔记】2.1 设计自己的计算机
  • vb房屋销售管理系统设计与实现
  • SpringCloud学习笔记(十三)_Zipkin使用SpringCloud Stream以及Elasticsearch
  • 重仓“AI”的百度迎来收获季?
  • Linux 通过 Docker 部署 Nacos 2.2.3 服务发现与配置中心
  • macOS上制作arm64的jdk17镜像
  • 对话永洪科技CEO何春涛:专注BI,决胜AI时代丨数据猿专访
  • Redis 数据类型详细解析
  • NOR型flash vs NAND型flash
  • 基于FPGA的图像sobel边缘提取算法开发,包括tb测试文件以及matlab验证代码
  • 设计模式-7--代理模式(Proxy Pattern)
  • 音频——I2S 左对齐模式(三)
  • css-grammar
  • ubuntu创建自定义开机服务