基于Python easyOCR的图片文字识别并在原图上框出识别位置

基于Python easyOCR的图片文字识别并在原图上框出识别位置

import json

import cv2
import easyocr
import numpy as np

if __name__ == '__main__':
    reader = easyocr.Reader(['ch_sim', 'en'], gpu=False, model_storage_directory='./EasyOCRModel')
    image_name = "img_ocr_test_1.PNG"
    image_org_path = "OCRimg/org/"
    image_out_path = "OCRimg/out/"
    text_json_list = []
    precision_json_list = []
    img = cv2.imread(image_org_path + image_name)
    result_text = reader.readtext(img)
    print("识别完成")
    print(result_text)
    for detection in result_text:
        bbox = detection[0]
        bbox = [(int(point[0]), int(point[1])) for point in bbox]
        text = detection[1]
        precision = detection[2]
        # utf8_text = text.encode('utf-8')
        text_json_list.append(text)
        precision_json_list.append(precision)
        # Draw the bounding box on the image
        cv2.polylines(img, [np.array(bbox)], isClosed=True, color=(0, 0, 255), thickness=2)
        # 以下是在方框上方加上识别的文字功能
        # Put the detected text on the image
        # cv2.putText(img,utf8_text.decode('utf-8'), (bbox[0][0], bbox[0][1] - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)

    # Save or display the modified image
    output_image_path = image_out_path + "result_" + image_name
    cv2.imwrite(output_image_path, img)
    print("绘制边界框并保存图片完成")

请添加图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值