python3百度文字ocr识别

"""
    读取文件
"""


def read_file(image_path):
    f = None
    try:
        f = open(image_path, 'rb')
        return f.read()
    except:
        print('read image file fail')
        return None
    finally:
        if f:
            f.close()


# 2. 接入百度智云文字识别服务
#如果已安装pip,执行pip install baidu-aip即可。
# 从aip中导入AipOcr
from aip import AipOcr

# 替换你的APP_ID,API_KEY,SECRET_KEY
APP_ID = ''
API_KEY = ''
SECRET_KEY = ''
# 新建一个AipOcr,并赋值给变量client
client = AipOcr(APP_ID, API_KEY, SECRET_KEY)

# 调用通用文字识别
# 如果有可选参数
# 创建字典options,并将可选参数detect_direction的值设置为"true"
options = {"detect_direction": "true"}
# 调用通用文字识别接口并把结果赋值给result
image = read_file("D:/image/verifyCode.png")
result = client.basicAccurate(image, options)
# 输出result
# print(result)
ending = result["words_result"]
print(ending)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值