paddleocr改写图片打印结果代码

修改原因:paddleocr自带的画框是下图所示(官方给出的一张图https://github.com/PaddlePaddle/PaddleOCR

 如果应用到工业上面,图片会非常大,且会遮挡原本不怎么清晰的文字,所以在tools/infer/utility.py改一下输出代码,直接添加下面代码

def draw_txt(image, boxes, txt=None, scores=None, drop_score=0.5,font_path="./doc/fonts/simfang.ttf"):
    if scores is None:
        scores = [1] * len(boxes)
    box_num = len(boxes)
    for i in range(box_num):
        if scores is not None and (scores[i] < drop_score or
                                   math.isnan(scores[i])):
            continue

    image1 = image
    for i in range(len(txt)):
        if txt == '':
            break
        if i == 0:
            image1 = cv2.putText(np.array(image),  txt[i],
            (250,250*(i+1)), cv2.FONT_HERSHEY_SIMPLEX,
            5.0, (255, 0, 0), 10)
        else:
            image1 = cv2.putText(np.array(image1),  txt[i],
            (250,250*(i+1)), cv2.FONT_HERSHEY_SIMPLEX,
            5.0, (255, 0, 0), 10)
   
    return np.array(image1)

然后tools/infer/predict_system.py中用draw_txt代替draw_ocr_box_txt(两个地方),上述代码编写文本位置(cv2.putText)可以自己调整自适应或者固定位置

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值