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 np


def cv_show(img):
    '''
    展示图片
    @param img:
    @param name:
    @return:
    '''
    cv2.namedWindow('name', cv2.WINDOW_KEEPRATIO)  # cv2.WINDOW_NORMAL | cv2.WINDOW_KEEPRATIO
    cv2.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.5
                             det_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.6
                                   text_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'])




  • 10
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要安装PaddleHub,首先需要安装paddlepaddle和paddlehub库。可以使用以下命令进行安装: ``` pip install paddlepaddle pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --default-timeout=100 paddlehub ``` \[1\] 安装完成后,可以使用PaddleHub进行预训练模型的搜索和应用。可以使用以下代码搜索所需的预训练模型: ``` import paddlehub as hub module_list = hub.ModuleList() print(module_list.search('文本分类')) ``` \[2\] PaddleHub是飞桨生态下的预训练模型应用工具库,内置了各种常用的预训练模型,可用于图像分类、目标检测、自然语言处理等领域。同时,PaddleHub还提供了各种实用的API和功能,例如Fine-tune API、Serving API等,可以大大地缩短使用深度学习模型进行开发的时间。\[3\] #### 引用[.reference_title] - *1* [python paddlehub的安装](https://blog.csdn.net/weixin_44387515/article/details/115428090)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [PaddleHub——AI开发者的得力助手:简介、安装、使用](https://blog.csdn.net/qq_37934722/article/details/130003089)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值