没有装aip 请CMD : pip install baidu-aip
但是你需要先创建百度的API也就是应用


来到应用列表

源代码如下
from aip import AipOcr
import re
""" 你的 APPID AK SK """
APP_ID = '18837678'
API_KEY = 'XIPPUjRrkwMCPuLL46LVQYs0'
SECRET_KEY = 'UOAkABVXI4peyCna31BxPcdGQOOxIeVN'
#对应的值记得替换
client = AipOcr(APP_ID, API_KEY, SECRET_KEY)
""" 读取图片 """
def get_file_content(filePath):
with open(filePath, 'rb') as fp:
return fp.read()
image = get_file_content('D://005.JPG')
""" 调用通用文字识别, 图片参数为本地图片 """
client.basicGeneral(image);
""" 如果有可选参数 """
options = {}
options["language_type"] = "CHN_ENG"
options["detect_direction"] = "true"
options["detect_language"] = "true"
options["probability"] = "true"
""" 带参数调用通用文字识别, 图片参数为本地图片 """
a = str(client.basicGeneral(image, options))
b = re.findall(r"'words': '(.*?)'}" ,a)
for result in b :
print(result)
发表评论: