图片文字处理 ocr

1、概述

有时候我们需要获取到图片的文字,但是了,图片的文字内容多元化,不同语言随时变化,需要一个利器来快速、准确识别到图片的文字还是有点难度,本文推荐python easyocr,相关环境部署,自行去学,都是很入门级别,该库的特点是:支持多语言,识别快,平均识别耗时:15秒(这个时间取决于你主机显卡的配置)

2、实例

def imageOcr(imageFile :str, lang="ch_sim"):
    """
    using easyOCR.
    :param image_path: 图片文件地址,或URL。
    :param lang: 指定图片中的文字语言,缺省是中文简体。
    :return: (识别到的文本列表, 通过";"分隔所有识别到的文本项组成的字符串)
    """

    start_times = time.time()
    # logging.getLogger("").setLevel(logging.ERROR)
    easyocr.easyocr.LOGGER.setLevel(logging.ERROR) #关闭warning告警。
    reader = easyocr.Reader([lang, 'en'])
    result = reader.readtext(imageFile, detail=0)
    strResult = ""
    if (result != None):
        for sitem in result:
            strResult = strResult + sitem + ";"
    print("识别图片耗时: {:.2f}秒".format(time.time() - start_times))
    return result, strResult

猜你喜欢

转载自blog.csdn.net/m0_56730596/article/details/127958509