本来准备自己写识别的,貌似现在能力不足,直接偷懒用百度的api吧
from aip import AipOcr """ 你的 APPID AK SK """
APP_ID = 'xxx'
API_KEY = 'xxx'
SECRET_KEY = 'xxx' 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('img.png') """ 调用通用文字识别, 图片参数为本地图片 """
rt = client.basicGeneral(image) words_result = rt['words_result'][0]['words']
print(words_result)