調用百度OCR模塊進行文字識別


1.登錄百度雲平台,創建應用

2.編寫代碼

from aip import  AipOcr
import  codecs
import os
#讀取圖片函數
def ocr(path):
    with open(path,'rb') as f:
        return  f.read()
def main():
    filename = "c.jpg"
    print("已經收到,正在處理,請稍后....")
    app_id = '16193547'
    api_key = 'B0R5gbezdGSzCY4oIlOpuLy8'
    secret_key = 'CyevG1PTfpPvkw9vwItPdya09GrzZ462'
    client = AipOcr(app_id,api_key,secret_key)
#讀取圖片
    image = ocr(filename)
#進程OCR識別
    dict1 = client.general(image)
#    print(dict1)
    with codecs.open(filename + ".txt","w","utf-8") as f:
        for i in dict1["words_result"]:
            f.write(str(i["words"] + "\r\n"))
    print ("處理完成")
if __name__ == '__main__':
    main()

 

效果圖:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM