# 在终端pip install baidu-aip
from aip import ocr
import json

# 注意 aipocr改成了ocr.AipOcr
# https://login.bce.baidu.com/ 
# 在百度智能云,申请ocr的api,得到APP_ID,API_KEY,SECRET_KEY。
APP_ID = '0000'
API_KEY = '00000000'
SECRET_KEY = '0000000000 '
client = ocr.AipOcr(APP_ID, API_KEY, SECRET_KEY)

def get_file_content(filePath):
    with open(filePath, 'rb') as fp:
        return fp.read()

def image2text(fileName):
    image = get_file_content(fileName)
    dic_result = client.basicGeneral(image)
    res = dic_result['words_result']
    result = ''
    for m in res:
        result = result + str(m['words'])
    return result

getresult = image2text('./2.png')
print(getresult)
Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐