Python調用百度AI 識別文字

# -*- coding: UTF-8 -*-
from aip import AipOcr
 
# 定義常量
APP_ID = ''
API_KEY = ''
SECRET_KEY = ''
 
# 初始化AipFace對象
aipOcr = AipOcr(APP_ID, API_KEY, SECRET_KEY)
 
# 讀取圖片
filePath = "test3.png"
 
def get_file_content(filePath):
    with open(filePath, 'rb') as fp:
        return fp.read()
 
# 定義參數變量
options = {
    'detect_direction': 'true',
    'language_type': 'CHN_ENG',
}
 
# 調用通用文字識別接口
result = aipOcr.basicGeneral(get_file_content(filePath), options)
print(result)
words_result=result['words_result']
for i in range(len(words_result)):
    print(words_result[i]['words'])

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章