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

[PaddlePaddle飞桨] PaddleOCR图像小模型部署

PaddleOCR的GitHub项目地址
推荐环境:

PaddlePaddle >= 2.1.2
Python >= 3.7
CUDA >= 10.1 
CUDNN >= 7.6

pip下载指令:

python -m pip install paddlepaddle-gpu==2.5.1 -i https://pypi.tuna.tsinghua.edu.cn/simple  pip install paddleocr==2.7.3

小模型配置代码:

from paddleocr import PaddleOCR# Paddleocr目前支持的多语言语种可以通过修改lang参数进行切换
# 例如`ch`, `en`, `fr`, `german`, `korean`, `japan`
OCR = PaddleOCR(lang="ch",use_angle_cls=True,use_gpu=True
)  # need to run only once to download and load model into memory

图片文件保存代码:

import io
import cv2
import os
import uuid
import numpy as np
def save_image_file(file_path, file_name, file_content):# 生成一个唯一的文件名unique_filename = str(uuid.uuid4()) + os.path.splitext(file_name)[1]# 确保目录存在if not os.path.exists(file_path):os.makedirs(file_path)try:# 将文件流转换为ndarraynparr = np.frombuffer(file_content.read(), np.uint8)file_nd_array = cv2.imdecode(nparr, cv2.IMREAD_COLOR)# 构建完整的文件路径file_path_with_file_name = os.path.join(file_path, unique_filename)# 保存图像到文件cv2.imwrite(filename=file_path_with_file_name, img=file_nd_array)return file_path_with_file_nameexcept Exception as e:print(f"Error saving file: {e}")return None

获取OCR结果代码:

import os
# 获取指定文件的OCR结果(数组)
def get_text_with_ocr(file_path_with_file_name):if not os.path.exists(file_path_with_file_name):return Noneocr_result = OCR.ocr(file_path_with_file_name)# for idx in range(len(ocr_result)):#     res = ocr_result[idx]#     for line in res:#         print(line)return ocr_result

图像文字提取代码:

# OCR(图像文字提取)
def optical_character_recognition(file_content, file_name):file_path_without_file_name = '.' + STATIC_IMAGE_PATH + "/"if not os.path.exists(file_path_without_file_name):os.makedirs(file_path_without_file_name)file_path_with_file_name = save_image_file(file_path_without_file_name, file_name, file_content)ocr_result = get_text_with_ocr(file_path_with_file_name)# 提取文本信息text_only = '\n'.join([item[1][0] for sublist in ocr_result for item in sublist])return text_only
http://www.lryc.cn/news/397104.html

相关文章:

  • C语言 | Leetcode C语言题解之第227题基本计算题II
  • kafka.common.KafkaException: Socket server failed to bind to xx:9092
  • 【JS+H5+CSS实现烟花特效】
  • uniapp小程序使用webview 嵌套 vue 项目
  • 命令模式在金融业务中的应用及其框架实现
  • WordPress的性能优化有哪些方法?
  • 【Python基础】代码如何打包成exe可执行文件
  • Golang | Leetcode Golang题解之第227题基本计算器II
  • 云端美味:iCloud中食谱与餐饮计划的智能存储方案
  • leetcode:1332. 删除回文子序列(python3解法)
  • 智慧交通的神经中枢:Transformer模型在智能交通系统中的应用
  • PCIe驱动开发(1)— 开发环境搭建
  • YOLOv10改进 | Conv篇 | CVPR2024最新DynamicConv替换下采样(解决低FLOPs陷阱)
  • 变革设计领域:Transformer模型在智能辅助设计中的革命性应用
  • Spring——配置说明
  • 禁用华为小米?微软中国免费送iPhone15
  • nginx初理解
  • FreeCAD源码分析:属性系统
  • C++入门 模仿mysql控制台输出表格
  • SpringBoot新手快速入门系列教程五:基于JPA的一个Mysql简单读写例子
  • 开源大势所趋
  • 智能无人机飞行控制系统:基于STM32的设计与实现(内附资料)
  • centos磁盘空间满了-问题解决
  • 宝塔:如何开启面板ssl并更新过期ssl
  • 大白话讲解AI大模型
  • pandas+pywin32操作excel办公自动化
  • 防火墙(ensp USG6000v)---安全策略 + 用户认证综合实验
  • Java使用POI导出后数字类型为常规类型,不能计算
  • 项目进度管理(5-1)常见的缓冲区监控方法
  • 构造函数语意学(The Semantics of Constructors)