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

paddlehub 文本检测使用

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.lryc.cn/news/275375.html

相关文章:

  • 负载均衡概述
  • C# WinForm MessageBox自定义按键文本 COM组件版
  • 基于SpringBoot微信小程序的宠物美容预约系统设计与实现
  • 在 docker 容器中配置双网卡,解决通讯的问题
  • uniapp中uview组件库CircleProgress 圆形进度条丰富的使用方法
  • Linux操作系统基础(12):Linux的Shell解释器
  • Android开发编程从入门到精通,安卓技术从初级到高级全套教学
  • HackTheBox - Medium - Linux - BroScience
  • `nginx/conf/nginx.conf`最简配置说明
  • 商务智能|描述性统计分析与数据可视化
  • 【游记】GDKOI2024
  • linux支持的零拷贝类型以及java对应的支持
  • 【TypeScript】声明文件
  • 基于Flutter构建小型新闻App
  • 利用python将excel文件转成txt文件,再将txt文件上传hdfs,最后传入hive中
  • 【自学笔记】01Java基础-07面向对象基础-02继承
  • 二分查找(一)
  • 【华为OD真题 Python】精准核酸检测
  • Springboot使用logback
  • 【REST2SQL】03 GO读取JSON文件
  • 数据库-MySQL 启动方式
  • YAML使用
  • 读书之深入理解ffmpeg_简单笔记2(初步)
  • ELK+kafka+filebeat企业内部日志分析系统搭建
  • 勒索检测能力升级,亚信安全发布《勒索家族和勒索事件监控报告》
  • 编译原理复习的有用链接
  • 不带控制器打包exe,转pdf文件时失败的原因
  • Python 注释的方法
  • webman插件创建
  • 大模型迎来“AppStore时刻”,OpenAI给2024的新想象