paddlehub 文本检测使用

news/2025/3/29 2:49:21/

PaddleHub负责模型的管理、获取和预训练模型的使用。
参考:https://github.com/PaddlePaddle/PaddleHub/tree/develop/modules/image/text_recognition/chinese_text_detection_db_server
在这里插入图片描述

 

在这里插入图片描述

 
import paddlehub as hub
import cv2
# from utils import  cv_show
import numpy as npdef cv_show(img):'''展示图片@param img:@param name:@return:'''cv2.namedWindow('name', cv2.WINDOW_KEEPRATIO)  # cv2.WINDOW_NORMAL | cv2.WINDOW_KEEPRATIOcv2.imshow('name', img)cv2.waitKey(0)cv2.destroyAllWindows()# 输入图片路径
image_path = 'pic/img.jpg' 
image = cv2.imread(image_path)gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
gray_padding = cv2.cvtColor( np.pad(gray, ((100, 100), (0, 0)), 'constant', constant_values=(255)), cv2.COLOR_GRAY2BGR)# 检测+识别
paddle_ocr = hub.Module(name="ch_pp-ocrv3")  #SVTR_LCNet     # mkldnn加速仅在CPU下有效 , enable_mkldnn=True
paddle_ocr.recognize_text(images=[gray_padding]   )ocr = hub.Module(name="chinese_ocr_db_crnn_server")#CRNN
r = ocr.recognize_text(images=[cv2.cvtColor(gray[:,:1250], cv2.COLOR_GRAY2BGR)],# paths=[],use_gpu=False,output_dir='ocr_result',visualization=True,box_thresh=0.5,text_thresh=0.5,angle_classification_thresh=0.9)# def recognize_text(images=[],
#                    paths=[],
#                    use_gpu=False,
#                    output_dir='ocr_result',
#                    visualization=False,
#                    box_thresh=0.6,
#                    text_thresh=0.5,
#                    angle_classification_thresh=0.9,
#                    det_db_unclip_ratio=1.5,
#                    det_db_score_mode="fast"):
# print('text',[[''.join(y['text'] for y in x['data'])]  for x in results])# 检测
text_detector_v3 = hub.Module(name="ch_pp-ocrv3_det")
result = text_detector_v3.detect_text(images=[gray_padding],output_dir='detection_result',box_thresh=0.6,visualization=True,det_db_unclip_ratio=2,#1.5det_db_score_mode='slow',)
box = result[0]['data'][1]
cv_show( gray_padding[box[0][1]:box[2][1],box[0][0]:box[1][0]])text_detector = hub.Module(name='chinese_text_detection_db_server')
result = text_detector.detect_text(images=[gray_padding] ,output_dir='detection_result',visualization = 'True',box_thresh=0.5,#0.6text_thresh=0.5,#0.6)
#det_db_thresh=0.1, det_db_box_thresh=0.4, det_db_unclip_ratio=2.0,det_db_score_mode='slow', use_dilation='True'
# def detect_text(images=[],
#                 paths=[],
#                 use_gpu=False,
#                 output_dir='detection_result',
#                 visualization=False,
#                 box_thresh=0.6,
#                 det_db_unclip_ratio=1.5,
#                 det_db_score_mode="fast")#可视框
for box in result[0]['data']:img = gray_padding[box[0][1]:box[2][1],box[0][0]:box[1][0]]cv_show(img)# for result in results:
#     data = result['data']
#     save_path = result['save_path']
#     for infomation in data:
#         print('text: ', infomation['text'], '\nconfidence: ', infomation['confidence'], '\ntext_box_position: ', infomation['text_box_position'])

http://www.ppmy.cn/news/1291943.html

相关文章

用贪心算法编程求解任务安排问题

题目:用贪心算法编程求解以下任务安排问题 一个单位时间任务是恰好需要一个单位时间完成的任务。给定一个单位时间任务的有限集S。关于S的一个时间表用于描述S中单位时间任务的执行次序。时间表中第1个任务从时间0 开始执行直至时间1 结束,第2 个任务从时…

【LeetCode】150. 逆波兰表达式求值(ASCII码)

今日学习的文章链接和视频链接 leetcode题目地址:150. 逆波兰表达式求值 代码随想录题解地址:代码随想录 题目简介 即将后缀表达式转换成中缀表达式并计算。 给你一个字符串数组 tokens ,表示一个根据 逆波兰表示法 表示的算术表达式。 …

[C#]C# OpenVINO部署yolov8图像分类模型

【官方框架地址】 https://github.com/ultralytics/ultralytics.git 【算法介绍】 YOLOv8 抛弃了前几代模型的 Anchor-Base。 YOLO 是一种基于图像全局信息进行预测的目标检测系统。自 2015 年 Joseph Redmon、Ali Farhadi 等人提出初代模型以来,领域内的研究者们…

计算机网络——网关或代理

1. 网关或代理的概念 网络中的代理服务器(proxy)或网关(passerelle)的概念。 在OSI模型的各个层次中,代理或网关充当中间实体,可以在不同的层次上提供连接和转发功能。 2. 代理或网关工作层次 在这种配置中…

opengl和directx中,渲染管线是什么?

在opengl 3D画图(渲染或图像处理)中,很多人都围绕着一个pipeline的词做很多解释,似乎明白这个词的含义成了入门必须要领悟的一道门槛。但实际上呢? 这都是因为翻译错误搞得大家非要解释一番的。好好的翻译工具不用&am…

Windows找不到文件‘chrome‘,请确定文件名是否正确后,再试一次。

本文主要记录遇到vscode运行HTML文件提示: Windows找不到文件‘chrome‘,请确定文件名是否正确后,再试一次。问题的解决办法。 目录 一、打开设置 二 、搜索Live Server Config (1)安装Live Server插件 &#xff0…

网络安全试题进阶——附答案

选择题 什么是CSRF攻击的全称? A. Cross-Site Request ForgeryB. Cross-Site ScriptingC. Credential Sniffing and Retrieval ForceD. Cyber Security and Risk Framework 哪种安全攻击利用用户的社交工程,诱使他们点击似乎是合法链接的恶意链接&#x…

MySQL数据管理(一)

一、列类型 列类型指规定数据库中该列存放的数据类型 列类型分类 数值类型字符串类型日期和时间型数值类型 数值类型 字符串类型 日期和时间类型 MySQL允许“不严格”语法,任何标点符号都可以作为日期部分之间的间隔符,如“24-01-03”、“24.01.03”…