"""
读取文件
"""
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)
|