调用百度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